React SDK
Reference guide for integrating feature flags into React applications.
Provider setup
Mount `FlagProvider` once at app root. Reuse a single client instance per app runtime.
TSTypeScript
import { FlagProvider, useFeatureFlag, useFlagClient } from "react-featureflags";
function Example() {
const enabled = useFeatureFlag("new-dashboard", false, { key: "user-123" });
const client = useFlagClient();
return enabled ? <DashboardV2 /> : <DashboardV1 />;
}Hooks
- `useFeatureFlag(flagKey, defaultValue, context)`
- `useFlagsReady()`
- `useAllFlags(context?)`
- `useFlagClient()`
Usage patterns
- Gate routes/components with default-safe fallbacks.
- Use shared context builders to keep targeting attributes consistent.
- Emit exposure callbacks only where analytics ownership is clear.
SSR notes
For SSR frameworks, prefer deterministic defaults during server render and re-evaluate on hydration.