SDKs
React SDK
FlagFixProvider and hooks on the browser client.
Cette page n’a pas encore de traduction française. Le texte anglais fait foi.
Last updated on
Peer dependency: React 18 or newer.
@flagfix/react wraps @flagfix/browser with a provider and hooks. Install @flagfix/react only; it pulls the browser package. Use a client key and the same apiHost as the browser SDK.
import { FlagFixProvider, useHasFeature, useTrack } from "@flagfix/react";
export function App({ serverFlagState }) {
return (
<FlagFixProvider
options={{
clientKey: process.env.NEXT_PUBLIC_FLAGFIX_CLIENT_KEY!,
apiHost:
process.env.NEXT_PUBLIC_FLAGFIX_API_HOST ??
"https://api.flagfix.io",
}}
serverFlagState={serverFlagState}
>
<Checkout />
</FlagFixProvider>
);
}| Hook | Behavior |
|---|---|
useFlagFix() | { client, status, startup, serverFlagState } |
useSdkStatus() | idle, starting, ready, failed |
useFlagFixClient() | Throws outside the provider |
useFlags() / useFlag(key) | Subscribed snapshot, SSR-safe |
useFlagMeta() / useFlagState() | Version and full state |
useHasFeature(key, fallback?) | Boolean. Fallback defaults to false. No exposure |
useTrack() | Before start, returns queued: false and reason: "NOT_STARTED" |
Pass client when you create it outside render. ownLifecycle then defaults to false, so unmount does not call shutdown. serverFlagState is the first paint and avoids a flash.
Cette page vous a-t-elle été utile ?