@trevosdk/browser/react wraps the browser SDK in a provider and a hook. react is an
optional peer dependency — install the SDK as normal:
Provider
Wrap your app once, as high as you can:apiKey should be stable
for the lifetime of the app.
Passing apiKey={undefined} disables the SDK entirely — a clean way to keep it off outside
production without branching your component tree.
Hook
Typed variants
Pass anExperiment from defineExperiment() and the return type narrows to a union, so
an unhandled arm is a compile error:
What renders on the first paint
This is the part worth understanding before you ship an experiment above the fold.- Returning visitors resolve from a warm local-storage cache and render the correct variant immediately.
- First-time visitors have no cache. They render
controlfor one paint, then swap to their assigned variant when config arrives.
- Resolve on the server. See Next.js — the first paint is already correct for everyone, with nothing hidden.
- Use the anti-flicker snippet. See Browser. Hides the page briefly rather than showing the wrong thing.
Accessing the client directly
track() and identify(). For reading variants, prefer useExperiment() —
it handles re-rendering when config arrives.
Identifying users
Callidentify() as soon as you know who the user is, typically in an effect after auth
resolves:
identify() after an experiment has
rendered can move the user to a different variant mid-session. Identify before rendering
anything under test.