How to implement feature flags in React
Provider, server snapshot, and an explicit exposure.
Last updated on
Server-only decisions belong in the Node guide. This path is for UI.
- Create a
CLIENT_SDKkey. - Optionally evaluate on the server with
@flagfix/nodeand passexportFlagState(). - Read
useHasFeaturein render. CalltrackExposurewhen the branch is shown.
"use client";
import { useFlagFixClient, useHasFeature } from "@flagfix/react";
export function CheckoutEntry() {
const client = useFlagFixClient();
const enabled = useHasFeature("new_checkout");
if (enabled) {
client.trackExposure("new_checkout");
return <p>New checkout</p>;
}
return <p>Classic checkout</p>;
}A feature flag is not an environment variable. The variable is fixed at build or boot. The flag changes when you publish, and the browser receives environment_updated on SSE.
Was this page useful?
Stream SSE d'invalidation de configuration GET
Stream `text/event-stream`. N'envoie pas le payload flags. Événement applicatif : - `event: environment_updated` - `id: <configurationVersion>` - `data: {"configurationVersion":12,"checksum":"…","environmentId":"…"}` Fan-out multi-instance via Redis pub/sub `flagfix:env:{environmentId}:config`. Heartbeats en commentaires SSE. Si Redis est down, aucun event live n'est garanti ; le SDK doit poller `/meta`.
How to use feature flags in Node.js
One process client, one identity per request.