Basic Usage
Get a configuration value that updates automatically:- 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:
Cache-First Loading
The hook uses a cache-first strategy:- Returns cached/default value immediately (no loading state)
- Fetches fresh value in background
- Updates when fresh value arrives
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:Error Handling
Handle fetch errors gracefully:value still contains the cached/default value. Your app doesn’t break.
Personalized Configurations
Pass properties to get user-specific values:Force Refresh Option
Skip cache and fetch directly:Feature Flag Example
A/B Testing Example
Multiple Configs
Need several configs? Use multiple hooks: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