useConfig
Hook to read the config.
- If no selector is passed, it returns the entire config object.
- If a selector is passed, it returns a given property and prevents unnecessary rerenders.
Call Signature
Section titled “Call Signature”useConfig<
TConfig>():TConfig
Defined in: packages/react/src/hooks.ts:34
Example:
const mySettings: MySettings = useConfig<MySettings>();⭐ Use with createHooks to avoid passing the TConfig generic explicitly:
export const {useConfig} = createHooks<MySettings>();
const mySettings: MySettings = useConfig();Type Parameters
Section titled “Type Parameters”TConfig
Section titled “TConfig”TConfig
The type of the configuration.
Returns
Section titled “Returns”TConfig
The entire configuration object.
Call Signature
Section titled “Call Signature”useConfig<
TConfig,TSelected>(selector):TSelected
Defined in: packages/react/src/hooks.ts:56
Pass a ConfigSelector function to access a specific property:
const theme: string = useConfig<MySettings, string>((c) => c.theme);⭐ Use with createHooks to avoid passing the TConfig generic explicitly:
export const {useConfig} = createHooks<MySettings>();
const theme: string = useConfig<string>((c) => c.theme);Type Parameters
Section titled “Type Parameters”TConfig
Section titled “TConfig”TConfig
The type of the configuration.
TSelected
Section titled “TSelected”TSelected
The selected value.
Parameters
Section titled “Parameters”selector
Section titled “selector”ConfigSelector<TConfig, TSelected>
A function that selects a value from the config.
Returns
Section titled “Returns”TSelected
The selected value.