New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-feature-toggles

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-feature-toggles

Feature toggle framework for react - down with feature branches

  • 3.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
502
increased by0.4%
Maintainers
2
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 01 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc