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-unleash-flags

v1.3.0

Published

React component for Unleash or Gitlab Feature Flags

Readme

React Unleash Flags

React component for Unleash or GitLab Feature Flags. This library provides a custom hook and react components to use in JavaScript or TypeScript projects.

Installation

Using NPM:

npm i --save react-unleash-flags

Configuration

The following config is required in order to fetch te flags from your Unleash or GitLab instance:

  • appName (the name of the app you will be running. Eg.: 'production', 'staging')
  • host (the location of the Unleash api. Eg.: ht​tps://my-unleash-url.com/api/)
  • url (Deprecated! Use host instead)
  • uri (the uri of the Unleash api. Eg.: /client/features) (this could be different if you want to point to an Unleash Proxy instead)
  • instanceId (the unique Unleash instance ID)
  • extraHttpHeaders (OPTIONAL extra http headers passed to the fetch call. For example, an Authorization header)

This configuration can be provided as an env variabe. The environment variables are:

  • REACT_APP_FLAGS_CTX_APP_NAME
  • REACT_APP_FLAGS_CTX_HOST
  • REACT_APP_FLAGS_CTX_URL (Deprecated! Use REACT_APP_FLAGS_CTX_HOST instead)
  • REACT_APP_FLAGS_CTX_URI
  • REACT_APP_FLAGS_CTX_INSTANCE_ID

The configuration can also be provide as a dict. (see examples below)

<FlagsProvider> with config in env vars

import React from 'react';
import ReactDOM from 'react-dom';
import { FlagsProvider } from 'react-unleash-flags';
import App from './App';

const root = document.getElementById('root');

if (root != null) {
    ReactDOM.render((
        <FlagsProvider>
            <App />
        </FlagsProvider>
    ), cakeRoot);
}

<FlagsProvider> with config in code

import React from 'react';
import ReactDOM from 'react-dom';
import { FlagsProvider } from 'react-unleash-flags';
import App from './App';

const root = document.getElementById('root');

// we can also define the config in code instead of using env vars
const flagConfig = {
    appName: 'production',
    host: 'https://...',
    uri: '/client/features',
    instanceId: '...',
    extraHttpHeaders: {
        Authorization: 'token123'
    }
};

// or if env vars are used for Unleash Flags settings, they can be combined 
// these settings will be appended to the settings from the env variables
const flagConfig = {
    extraHttpHeaders: {
        Authorization: 'token123'
    }
};

if (root != null) {
    ReactDOM.render((
        <FlagsProvider config={flagConfig} >
            <App />
        </FlagsProvider>
    ), cakeRoot);
}

Usage

Make sure you've setup the <FlagsProvider> correctly.

Custom useFlag Hook

// load the flag using the useFlag hook
const flag = useFlag(name);

// a flag that does not exist will return undefined
if (flag && flag.enabled) {
    ...
}

React <FeatureFlag> component

Attributes:

  • name: string - the name of the flag
  • defaultValue (optional, default=false): boolean - the value when the flag does not exist or when it is still loading
  • invert (optional, default=false): boolean - if true, the child elements will render when the feature is disabled

The <FeatureFlag> component can handle both JSX and a function as child elements:

<FeatureFlag name="test-flag">
    hello, this flag is enabled
</FeatureFlag>

<FeatureFlag name="test-flag" invert={true}>
    hello, this flag is disabled
</FeatureFlag>

<FeatureFlag name="test-flag">
    {(flag) => { console.log(flag); }}
</FeatureFlag>

Links

  • Unleash (https://unleash.github.io/)
  • GitLab Feature Flags (https://docs.gitlab.com/ee/user/project/operations/feature_flags.html)