Skip to main content

Basic Usage

Get a configuration value that updates automatically:
What you get:
  • Instant access to cached or default values
  • Background refresh for fresh data
  • Automatic re-render when config changes

Return Values

useConfig returns an object with:
value: The configuration value (string or undefined) isRefreshing: True while fetching fresh data error: Error object if fetch failed refresh: Function to manually refresh

Cache-First Loading

The hook uses a cache-first strategy:
  1. Returns cached/default value immediately (no loading state)
  2. Fetches fresh value in background
  3. Updates when fresh value arrives
Your UI renders immediately with cached values. The isRefreshing indicator is optional - show it if you want users to know fresh data is loading.

With Default Values

Set defaults in the provider for instant access:

Manual Refresh

Force refresh a configuration:
This fetches the latest value from the API, bypassing cache.

Error Handling

Handle fetch errors gracefully:
If fetch fails, value still contains the cached/default value. Your app doesn’t break.

Personalized Configurations

Pass properties to get user-specific values:
The dashboard evaluates rules based on these properties and returns matching values.

Force Refresh Option

Skip cache and fetch directly:
Note: This still returns cached value immediately, but guarantees a fresh fetch happens.

Feature Flag Example

Toggle features remotely without code changes.

A/B Testing Example

Show different experiences to different users.

Multiple Configs

Need several configs? Use multiple hooks:
Each hook independently manages its value and re-renders only when its config changes.

Performance

The hook is optimized to prevent unnecessary re-renders:
  • Only re-renders when the specific config changes
  • Function references (like refresh) are stable
  • Safe to use in multiple components without performance cost

Next Steps

useAllConfigs

Get all configurations at once

Remote Config

Learn about remote configuration

A/B Testing Guide

Build A/B tests with configs