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-toggles

v3.0.3

Published

Feature toggle framework for react - down with feature branches

Downloads

1,964

Readme

react-feature-toggles

Declarative feature toggle framework for react / react-native, allowing you to get rid of test complications, and branching logic.

Build Status

npm version

Install

npm install --save react-feature-toggles

Usage

Wrap your app in the FeatureToggleProvider and pass in a list of toggles, then use the FeatureToggle component throughout your application.

Both FeatureToggleProvider and FeatureToggle must have only one child, this is so that the library isn't rendering additional elements on your behalf and making assumptions about your needs e.g you may want an <li> rather than a <div>.

import React from 'react';
import ReactDOM from 'react-dom';
import { FeatureToggleProvider, FeatureToggle } from '../lib/index';

const toggleNames = {
  SHOW_HELLO_WORLD: 'showHelloWorld'
  // ... add more here
};

const toggles = {
  // Try setting this to true
  [toggleNames.SHOW_HELLO_WORLD]: false
  // ... add more here
};

const ExampleComponent = () => (
  <FeatureToggleProvider featureToggleList={toggles}>
    <div>
      <h1>Toggling Example</h1>
      <FeatureToggle featureName={toggleNames.SHOW_HELLO_WORLD}>
        <p>Hello World</p>
      </FeatureToggle>
      <FeatureToggle featureName={toggleNames.SHOW_HELLO_WORLD} showOnlyWhenDisabled>
        <p>Sorry, toggle is off</p>
      </FeatureToggle>
    </div>
  </FeatureToggleProvider>
);

ReactDOM.render(<ExampleComponent />, document.getElementById('example'));

Redux

To use with redux you may want to do something like:

const mapStateToProps = state => ({
  featureToggleList: state.features,
});

const ConnectedFeatureToggleProvider = connect(mapStateToProps)(FeatureToggleProvider);

And then use the connected provider in place of the normal provider.

Building the example

  • Clone this repo
  • Run npm install
  • Run npm run build-example
  • Open example/example.html in the browser
  • Play around with the toggle values

Making a pull request?

  • Make sure you've run npm run ci-build first

Changes

  • Version 3.0.3 Update dev dependencies
  • Version 3.0.2 Update readme
  • Version 3.0.1 Remove self dependency (:/)
  • Version 3.0.0 Upgrade peer deps (and internal deps) for React 16
  • Version 2.0.3 Switch proptypes from React.PropTypes to the dedicated proptypes library
  • Version 2.0.2 Ensures an undefined toggle is treated a false
  • Version 2.0.1 Removes a containing div around the provider children, should you need this div, please add it in yourself.