React Integration Guide

React Feature Flags

Ship features safely in React with instant rollouts and zero redeployments

Quick Start

1. Get your API key

Sign up at flagbit.anethoth.com to get your SDK key. The free tier includes 1,000 evaluations/day.

2. Install (optional)

npm install flagbit-client

3. Evaluate flags

import { useState, useEffect } from 'react';

// Evaluate a feature flag via FlagBit API
async function getFlag(flagKey, context = {}) {
  const res = await fetch(
    'https://flagbit.anethoth.com/api/v1/evaluate', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-SDK-Key': process.env.REACT_APP_FLAGBIT_SDK_KEY
    },
    body: JSON.stringify({
      flag_key: flagKey,
      context: context
    })
  });
  const data = await res.json();
  return data.value;
}

// React hook for feature flags
function useFeatureFlag(flagKey, defaultValue = false) {
  const [enabled, setEnabled] = useState(defaultValue);

  useEffect(() => {
    getFlag(flagKey, { user_id: getCurrentUserId() })
      .then(val => setEnabled(val))
      .catch(() => setEnabled(defaultValue));
  }, [flagKey]);

  return enabled;
}

// Usage in a component
function Dashboard() {
  const showNewChart = useFeatureFlag('new-analytics-chart');

  return (
    <div>
      <h1>Dashboard</h1>
      {showNewChart ? <NewAnalyticsChart /> : <LegacyChart />}
    </div>
  );
}

Use Cases for React

Gradual Rollouts

Release a new React component to 10% of users first, then ramp up to 100% as you gain confidence.

A/B Testing UI

Show different UI variants to different user segments and measure which converts better.

Kill Switch

Instantly disable a broken feature in production without deploying — just toggle the flag in FlagBit.

Beta Features

Gate premium features behind flags and enable them only for beta testers or paying customers.

How FlagBit Works

1

Create a Flag

Define flags in your FlagBit dashboard with targeting rules and rollout percentages.

2

Evaluate in Code

Call the evaluate endpoint from your React app with user context for targeted rollouts.

3

Toggle Instantly

Enable, disable, or adjust rollouts in real-time. No redeployment needed.

FAQ

FlagBit's evaluate endpoint responds in under 50ms. Cache flag values on the client to avoid per-render API calls.

Yes — use FlagBit in getServerSideProps for server-side evaluation, or in client components with the useFeatureFlag hook pattern shown above.

Use a default value (usually false) while the flag is loading. This ensures features gracefully degrade if the API is slow.

Yes — pass user attributes in the context object (user_id, email, plan, country) and set targeting rules in FlagBit.

Start using feature flags in React

Free tier includes 1 project, 10 flags, and 1,000 evaluations/day. No credit card required.

Get Your Free API Key