useDynamicConfig.ts
hooks/useDynamicConfig.ts
No strong subsystem tag
23
Lines
703
Bytes
1
Exports
2
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 23 lines, 2 detected imports, and 1 detected exports.
Important relationships
Detected exports
useDynamicConfig
Keywords
reactdefaultvalueconfignamegetdynamicconfig_blocks_on_inithookconfigthenwhenconfigvaluesetconfigvalue
Detected imports
react../services/analytics/growthbook.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
import React from 'react'
import { getDynamicConfig_BLOCKS_ON_INIT } from '../services/analytics/growthbook.js'
/**
* React hook for dynamic config values.
* Returns the default value initially, then updates when the config is fetched.
*/
export function useDynamicConfig<T>(configName: string, defaultValue: T): T {
const [configValue, setConfigValue] = React.useState<T>(defaultValue)
React.useEffect(() => {
if (process.env.NODE_ENV === 'test') {
// Prevents a test hang when using this hook in tests
return
}
void getDynamicConfig_BLOCKS_ON_INIT<T>(configName, defaultValue).then(
setConfigValue,
)
}, [configName, defaultValue])
return configValue
}