Socket
Socket
Sign inDemoInstall

react-awesome-feature-toggles

Package Overview
Dependencies
30
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-awesome-feature-toggles

Simple feature toggles for react and react router


Version published
Weekly downloads
21
decreased by-50%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

build-status Version

MIT license airbnb code style


This plugin provides a feature toggle component

Features

  • Set feature config and check if a toggle is enabled
  • Use FeatureToggle Component to render children if a toggle is enabled
  • Use FeatureToggle Component to render sub-routes if a toggle is enabled

Getting Started

Install react-awesome-feature-toggles using npm:

npm install --save react-awesome-feature-toggles

Usage

Setting your feature config:

Use setFeatureConfig to set you config. It accepts an object with keys which will be used as the names of your features. It currently does not (yet) support nested objects

  import { setFeatureConfig } from 'react-awesome-feature-toggles'

  setFeatureConfig({
    "awesome.feature": true,
    "disabled.feature": false
  })

Using the FeatureToggle Component

Now use the <FeatureToggle /> Component to conditionally render children

  import { FeatureToggle } from 'react-awesome-feature-toggles'

  return (
    <div>
      <FeatureToggle name="awesome.feature">
        This text is rendered
      </FeatureToggle>
      <FeatureToggle name="disabled.feature">
        This text is not rendered
      </FeatureToggle>
    </div>
  )

You can also use <FeatureToggle /> to enable routes conditionally. The disabled routes are taken from the route structure just like as if they do not exist:

  import { Route, IndexRoute, match } from 'react-router'
  import { FeatureToggle } from 'react-awesome-feature-toggles'

  const routes = (
    <Route name="home" path="/">
      <IndexRoute />
      <FeatureToggle name="awesome.feature">
        <Route name="route1" path="route1" />
      </FeatureToggle>
      <FeatureToggle name="disabled.feature">
        <Route name="route2" path="route2" />
      </FeatureToggle>
    </Route>)

This would lead to a router that matches /route1 but not /route2.

License

MIT

Keywords

FAQs

Last updated on 09 May 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc