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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-feature-flipper

v2.0.2

Published

React HOC for feature toggling

Downloads

8

Readme

React Feature Flipper

Build Status

React Feature Flipper HOC.

Feature Toggles (often also refered to as Feature Flags) are a powerful technique, allowing teams to modify system behavior without changing code.

-- Martin Fowler

If you don't know about feature flippers (feature toggles/flags) please read here from Martin Fowler and here from wikipedia.

TL:DR; this technique allows you to activate/de-active your feature without changing code while your application is running. And this can be done on certain criteria and time. It can be applied to certain individuals (users) or you can use it for A/B testing.

This library offers you a React HOC (high order component) to add your project.

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

yarn add react-feature-flipper

Usage

There are 2 HOCs:

featureFlipper (or alternatively featureFlipperStatic with named import)

This component is the default export of a library.

  • Import featureFlipper into your React project with default import.
import featureFlipper from 'react-feature-flipper';

Code below enables <HelloWorld /> component wherever used. Second item in array param enables/disables your component.

export default featureFlipper([HelloWorld, true])

featureFlipperPromise

  • Import featureFlipperPromise into your React project.
import { featureFlipperPromise } from 'react-feature-flipper';

And use it as shown below.

  • Pass required parameters to featureFlipperPromise method call with an array items:
    • First (required): Your Component
    • Second (required): Promise to return all feature flippers. It should be an object with a property features having feature flippers (array of string).
    • Third (optional): The name of the feature flipper (string) you want to bind to a Component. If you omit this param then HOC uses the name of the component to find required feature flipper. eg. It would be HelloWorld for the example below.
export default featureFlipper([
  HelloWorld,
  new Promise(resolve => 
    resolve({
      features: ['hello_world', 'blabla']
    })),
  'hello_world'
])

Usage with other HOCs

You can pass wrapped component directly into featureFlipper. for example with redux connect

export default featureFlipper([
  connect(mapStateToProps, mapDispatchToProps)(HelloWorld),
  true
]);

I recommend you to create another file if you would like to enable feature flippers for multiple components. It would be easier to track down feature flipped components.

import featureFlipper from 'react-feature-flipper';
import { default as FooBase } from './Foo';
import { default as BarBase } from './Bar';

export const Foo = featureFlipper([FooBase, true]);
export const Bar = featureFlipper([BarBase, false]);

Tools

If you would like to see the example (example is located in examples/FeatureFlipper folder) running on your local machine then:

git clone [email protected]:erhangundogan/react-feature-flipper.git
cd react-feature-flipper
yarn
yarn dev

browse http://localhost:9000

Other commands:

yarn build
yarn test
yarn lint

LICENSE

MIT