npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@flagcontrol/react

v0.2.7

Published

React SDK for FlagControl feature flag management

Readme

@flagcontrol/react

The React SDK for FlagControl - feature flag and remote configuration management.

npm License: MIT

Installation

npm install @flagcontrol/react

Usage

1. Wrap your app with FlagProvider

Wrap your application root with FlagProvider. Pass your SDK key in the config prop. You can also pass an initial context or initialFlags for SSR support.

import { FlagProvider } from '@flagcontrol/react';

function App() {
  return (
    <FlagProvider
      config={{
        sdkKey: 'YOUR_SDK_KEY',
      }}
      context={{
        userId: 'user-123',
        plan: 'pro'
      }}
    >
      <YourComponent />
    </FlagProvider>
  );
}

2. Server-Side Rendering (SSR) & Hydration

If you are using a framework like Next.js, TanStack Start, or Remix, you can evaluate flags on the server using @flagcontrol/node and pass them to the client to prevent layout shifts.

Server Component / Loader (Next.js Example)

import { FlagControl } from "@flagcontrol/node";
import { ClientLayout } from "./client-layout";

export default async function Layout({ children }) {
  const nodeClient = new FlagControl({ sdkKey: process.env.FLAGCONTROL_SECRET_KEY });
  const serverFlags = await nodeClient.getAllFlags({ userId: "user-123" });

  return <ClientLayout initialFlags={serverFlags}>{children}</ClientLayout>;
}

Client Component (client-layout.tsx)

"use client";
import { FlagProvider } from "@flagcontrol/react";

export function ClientLayout({ initialFlags, children }) {
  return (
    <FlagProvider 
      config={{ sdkKey: process.env.NEXT_PUBLIC_FLAGCONTROL_CLIENT_KEY }} 
      initialFlags={initialFlags}
    >
      {children}
    </FlagProvider>
  );
}

3. Use flags in your components

Use the useFlag hook to evaluate flags. It handles updates automatically when flags change or context is updated.

import { useFlag } from '@flagcontrol/react';

function YourComponent() {
  const isEnabled = useFlag('new-feature', false);

  if (isEnabled) {
    return <div>New Feature Enabled!</div>;
  }

  return <div>Old Feature</div>;
}

You can also pass a specific context to useFlag for per-flag evaluation overrides:

const isMobile = useFlag('mobile-feature', false, { device: 'mobile' });

4. Context Management

You can update the global context dynamically, for example after user login. This triggers a re-fetch of flags.

import { useFlagControl } from '@flagcontrol/react';

function LoginButton() {
  const client = useFlagControl();

  const handleLogin = async (user) => {
    await client.identify({
      userId: user.id,
      email: user.email,
      role: user.role
    });
  };

  return <button onClick={() => handleLogin(newUser)}>Login</button>;
}

5. Real-time Updates

The React SDK automatically subscribes to changes. You don't need to do anything special; useFlag hooks will re-render your components when flag definitions change or when you validly call identify.

To manually subscribe to changes or force a reload:

const client = useFlagControl();

useEffect(() => {
  const unsubscribe = client.subscribe(() => {
    console.log('Flags updated');
  });
  return unsubscribe;
}, [client]);

// Force reload
await client.reload();

6. List Management

You can manage targeting lists directly from the client if needed (e.g. for admin panels or user opt-ins).

import { useFlagControl } from '@flagcontrol/react';

function BetaOptIn() {
  const client = useFlagControl();

  const handleJoinBeta = async () => {
    await client.addToList('beta-users', { key: 'user-123' });
    // Flags will be re-evaluated automatically next time they are fetched or context changes
  };

  return <button onClick={handleJoinBeta}>Join Beta</button>;
}

Related Packages

| Package | Description | |---------|-------------| | @flagcontrol/core | Core SDK logic | | @flagcontrol/node | Node.js SDK for server-side | | flagcontrol | CLI for TypeScript type generation |

Documentation

For full documentation, visit flagcontrol.com/docs.

License

MIT