FlagFix
Guides

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.

  1. Create a CLIENT_SDK key.
  2. Optionally evaluate on the server with @flagfix/node and pass exportFlagState().
  3. Read useHasFeature in render. Call trackExposure when 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?