React SDK API Reference
Complete reference for all exports, types, and interfaces in@superflag-sh/react.
Components
SuperflagProvider
Context provider that wraps your app and manages flag state.| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
clientKey | string | No | env var | Public client key (pub_*) |
ttlSeconds | number | No | 60 | Cache TTL in seconds |
storage | StorageAdapter | No | localStorage | Custom storage adapter |
children | ReactNode | Yes | - | React children |
clientKey is not provided, the provider looks for:
process.env.NEXT_PUBLIC_SUPERFLAG_CLIENT_KEY(Next.js)import.meta.env.VITE_SUPERFLAG_CLIENT_KEY(Vite)process.env.REACT_APP_SUPERFLAG_CLIENT_KEY(CRA)
Hooks
useFlag
Get the value of a feature flag with type safety.| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Flag key name |
fallback | T | No | Default value if flag not found |
T, or fallback if provided, or undefined.
Examples:
useFlags
Get the current SDK state.| Field | Type | Description |
|---|---|---|
flags | Flags | All flags as key-value pairs |
status | SuperflagStatus | Current SDK status |
ready | boolean | Shorthand for status === 'ready' |
loading | boolean | Shorthand for status === 'loading' |
version | number | null | Config version number |
etag | string | null | ETag from last fetch |
lastFetchedAt | number | null | Timestamp of last fetch |
error | string | null | Error message if failed |
Types
SuperflagStatus
| Status | Description |
|---|---|
idle | Initial state before fetching |
loading | Fetching flags from API |
ready | Flags loaded successfully |
error | Failed to load flags |
rate-limited | Monthly quota exceeded |
SuperflagState
Flags
StorageAdapter
Custom storage adapter interface for persisting flags.SuperflagProviderProps
Constants
Cache Key
The SDK stores cached config under this localStorage key:Exports
All exports from@superflag-sh/react: