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

react-flaggy

v1.0.0

Published

Modern, type-safe feature flag library for React with hooks, SSR support, percentage rollouts, and A/B testing

Downloads

43

Readme

React Flaggy

A “Flaggy” name for a not-at-all-flaggy library. A sturdy, type-safe React feature flag solution with hooks, SSR support, DevTools, percentage rollouts, user targeting, and A/B testing.

npm version TypeScript License: MIT

Features

  • Modern Hooks API - useFeatureFlag, useFeatureFlags, useFeatureVariant
  • Full TypeScript Support - Complete type safety with declaration merging
  • Multiple Flag Formats - Objects, arrays, nested structures
  • Async Loading - Load flags from remote sources with auto-refresh
  • User Targeting - Percentage rollouts and attribute-based targeting
  • A/B Testing - Built-in variant selection for experiments
  • DevTools - Debug panel with override capabilities
  • SSR Support - Next.js, Remix, and other SSR frameworks
  • Zero Dependencies - Lightweight and fast

Installation

npm install react-flaggy
# or
yarn add react-flaggy

Quick Start

import { FlagsProvider, useFeatureFlag } from 'react-flaggy';

// Define your flags
const flags = {
  newDashboard: true,
  betaFeatures: false,
  darkMode: true
};

function App() {
  return (
    <FlagsProvider features={flags}>
      <MyApp />
    </FlagsProvider>
  );
}

function MyApp() {
  const hasNewDashboard = useFeatureFlag('newDashboard');
  return hasNewDashboard ? <NewDashboard /> : <LegacyDashboard />;
}

Core API

Hooks

// Check a single flag
const isEnabled = useFeatureFlag('featureName');

// Get all flags
const allFlags = useFeatureFlags();

// A/B testing with variants
const { enabled, variant, value } = useFeatureVariant('experiment');

Components

// Declarative feature flag
<Feature name="newFeature" fallback={<Old />}>
  <NewFeature />
</Feature>

// Provider with async loading
<FlagsProvider
  loadFeatures={async () => fetch('/api/flags').then(r => r.json())}
  user={{ id: 'user-123' }}
>
  <App />
</FlagsProvider>

HOC Pattern

const AdminPanel = withFeatureFlag('adminAccess')(Dashboard);

Advanced Usage

Multiple Flag Formats

// Simple object (recommended)
const flags = { feature1: true, feature2: false };

// Nested structure
const flags = {
  admin: { dashboard: true },
  checkout: { expressCheckout: true }
};
// Access: useFeatureFlag('admin/dashboard')

// String array (all enabled)
const flags = ['feature1', 'feature2'];

// Advanced config with rollouts
const flags = {
  premium: {
    enabled: true,
    rollout: { percentage: 25 },
    value: { theme: 'dark' }
  }
};

User Targeting & Rollouts

const flags = {
  premiumFeature: {
    enabled: true,
    rollout: {
      percentage: 10,                    // 10% rollout
      userIds: ['vip-1'],                // Always include
      emailDomains: ['@company.com'],    // Internal users
      attributes: { plan: 'premium' }    // Targeting
    }
  }
};

<FlagsProvider
  features={flags}
  user={{
    id: 'user-123',
    email: '[email protected]',
    attributes: { plan: 'premium' }
  }}
>
  <App />
</FlagsProvider>

A/B Testing

const flags = {
  experiment: {
    enabled: true,
    variants: [
      { name: 'control', weight: 50 },
      { name: 'variant-a', weight: 50, value: { color: 'blue' } }
    ]
  }
};

function Button() {
  const { variant, value } = useFeatureVariant('experiment');
  return <button style={{ color: value?.color }}>Click</button>;
}

TypeScript Support

// feature-flags.d.ts - Get autocomplete!
declare module 'react-flaggy' {
  export interface FeatureFlagNames {
    'newDashboard': true;
    'betaFeatures': true;
  }
}

// Now with type safety
const isEnabled = useFeatureFlag('newDashboard'); // Autocomplete
const invalid = useFeatureFlag('typo');            // Type error

DevTools

import { FeatureFlagsDevTools } from 'react-flaggy';

<FlagsProvider
  features={flags}
  devTools={{
    enabled: true,
    allowUrlOverrides: true,          // ?ff_override=flag:true
    allowLocalStorageOverrides: true
  }}
>
  <App />
  {process.env.NODE_ENV === 'development' && <FeatureFlagsDevTools />}
</FlagsProvider>

SSR & Next.js

Next.js App Router

// app/providers.tsx
'use client';
export function Providers({ children, flags }) {
  return <FlagsProvider features={flags}>{children}</FlagsProvider>;
}

// app/layout.tsx
export default function RootLayout({ children }) {
  const flags = { newFeature: true };
  return (
    <html><body><Providers flags={flags}>{children}</Providers></body></html>
  );
}

Next.js Pages Router

import { FlagsProvider, hydrateFlags } from 'react-flaggy';

export default function App({ Component, pageProps, flags }) {
  return (
    <FlagsProvider features={flags} hydrateFrom="__FEATURE_FLAGS__">
      <Component {...pageProps} />
    </FlagsProvider>
  );
}

Full Documentation

For complete API documentation, examples, and guides, see the docs folder or visit our GitHub repository.

Contributing

Contributions welcome! Please open an issue or PR.

License

MIT