React Feature Toggles
Feature Toggles for React Projects.
Version 2
This is version 2, it contains many breaking changes from version 1.
Requirements
React Feature Toggles attempts to satisfy the following requirements:
- Universal - server and client side
- Conditionally render components based on the presence or absence of a specific feature
Install
npm install --save @paralleldrive/react-feature-toggles
Basic Usage
API
Components
FeatureToggles
FeatureToggles
is a provider component.
props
- features = []
Feature
Feature
is a consumer component.
If the feature is enabled then the activeComponent will render else it renders the inactiveComponent.
Feature takes these props
- name = ""
- inactiveComponent = noop
- activeComponent = null
Alternatively, you can use Feature
as a render prop component. Do this by passing a function as the children to the Feature
component. Note: This will only work if an activeComponent
is not provided.
Higher Order Components
withFeatureToggles
({ features = [...String] } = {}) => Component => Component
You can use withFeatureToggles
to compose your page functionality.
Depending on your requirements, you might need something slightly different than the default withFeatureToggles
. The default withFeatureToggles
should serve as a good example to create your own.
configureFeature
(inactiveComponent: Component) => (name: String) => (activeComponent: Component) => Component
configureFeature
is a higher order component that allows you to configure a Feature
component.
Enabling features from the URL
In v2, query logic has been moved out of the provider component. You should now handle this logic before passing features to FeatureToggles