Skip to content

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.

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();

TConfig

The type of the configuration.

TConfig

The entire configuration object.

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);

TConfig

The type of the configuration.

TSelected

The selected value.

ConfigSelector<TConfig, TSelected>

A function that selects a value from the config.

TSelected

The selected value.