Overview
In this guide you add typed hooks to a React app: bind them once withcreateShipdReact, provide a browser client, identify the signed-in user, and read flags in components. Hooks re-render when a new snapshot arrives or the identity changes.
This page builds on Browser. For the App Router, also read Next.js.
Bind hooks once
CallcreateShipdReact in one client-only module and import hooks from there. Hooks from a different createShipdReact call can’t read this provider.
src/lib/shipd-react.ts
src/generated/flags.ts. Generated files contain types only, so server code can import FlagDefinitions without pulling in React.
Create the client and provider
src/main.tsx
Identify from your auth layer
src/components/IdentifyUser.tsx
<IdentifyUser /> inside ShipdProvider. Every hook re-renders with the new identity. See Identify users.
Read flags
src/components/CheckoutNav.tsx
useFlag("search-variant") and useVariant("new-checkout") are compile errors.
All hooks throw if they’re called outside
ShipdProvider.
Handle the loading state
Before the first snapshot loads, hooks returndefaults. useReady() is false until the snapshot or cached snapshot loads, or readyTimeoutMs elapses. Use it to show a skeleton instead of briefly rendering the default path.
If a default is an acceptable first render (for example, false hides an unreleased feature), you can skip useReady(). The component re-renders when the snapshot arrives.