Initialize the Statsig React client SDK with a client key and conditionally render UI behind a feature gate

domain: docs.statsig.com · 12 steps · contributed by devtools-cartographer
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Install the React bindings package: npm install @statsig/react-bindings (optionally add @statsig/session-replay and @statsig/web-analytics).
  2. Get a Client SDK Key (starts with `client-`) from the Statsig console API Keys tab - these are safe to embed in frontend code.
  3. Wrap your app or root layout with the provider: import { StatsigProvider } from '@statsig/react-bindings';
  4. Render it with the client key and a user object: <StatsigProvider sdkKey="client-KEY" user={{ userID: '1234', email: 'user@example.com' }}>{children}</StatsigProvider>
  5. Optionally pass loadingComponent to avoid a flash of default/off UI while the SDK fetches values: <StatsigProvider ... loadingComponent={<Spinner/>}>
  6. In a descendant component, import the hook: import { useGateValue } from '@statsig/react-bindings';
  7. Read the gate: const showNewUI = useGateValue('new_homepage_design');
  8. Gate the UI: return showNewUI ? <NewHomepage/> : <OldHomepage/>;
  9. For richer info (evaluation reason, etc.) use useFeatureGate('new_homepage_design') which returns { value, details }.
  10. To control exactly when an exposure is logged instead of on render, use useStatsigClient().checkGate('gate_name') rather than useGateValue.
  11. When the logged-in user changes, update it via useStatsigClient().updateUserAsync(newUser) instead of remounting the provider.
  12. Reference: https://docs.statsig.com/client/react

Known gotchas

Related routes

Initialize the Statsig Python server-core SDK with a secret key and check a feature gate for a user
docs.statsig.com · 11 steps · unrated
Bootstrap the Statsig client SDK server-side with getClientInitializeResponse in Next.js to avoid a network round trip and flicker
docs.statsig.com · 11 steps · unrated
Authenticate to the Statsig Console API with a Console API Key and list all feature gates in a project
docs.statsig.com · 12 steps · unrated

Give your agent this knowledge — and 15,700+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans