Skip to main content
useConfig(key) returns one configuration value. The first render shows the cached value or the default. The hook then fetches the current value from the API and re-renders when it arrives. Configuration values are strings. Read Remote configuration.

Signature

Options

Result

Cache-first behavior

  1. On the first render, the hook reads client.getConfig(key). The result comes from the cache or from defaultConfigurations. There is no loading state.
  2. After mount, the hook calls client.fetchConfig with the options. When the response holds the key, value updates and the component re-renders.
  3. The hook subscribes to the configuration change listener of the client. When any fetch or the refresh timer changes the key, value updates.
  4. When the fetch fails, error holds the failure and value keeps the cached or default value.
The hook fetches again when key, forceRefresh, immediateKeys, or properties change.
Define properties and immediateKeys outside the component or memoize them with useMemo. The hook compares them by reference. An object literal in the render body is a new object on every render, so the hook fetches on every render.

Default values

Set defaultConfigurations on the provider. The first render shows the default, also when the device is offline.

Feature flag

Values are strings. Compare with 'true'. Read Feature flags.

Personalized value

Refresh and errors

Several keys

Call useConfig one time per key. Each call re-renders only when its own key changes. For many keys, or to iterate over all keys, read useAllConfigs.