Declarative feature toggle framework for react / react-native, allowing you to get rid of test complications, and branching logic.
npm install --save react-feature-toggles
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 `
`.
import React from 'react';
import ReactDOM from 'react-dom';
import { FeatureToggleProvider, FeatureToggle } from 'react-feature-toggles';
const toggles = {
// Try setting this to true
SHOW_HELLO_WORLD: false
// ... add more here
};
const ExampleApp = () => (
<FeatureToggleProvider featureToggleList={toggles}>
<h1>Toggling Example</h1>
<FeatureToggle featureName={toggleNames.SHOW_HELLO_WORLD}>
Hello World
</FeatureToggle>
<FeatureToggle featureName={toggleNames.SHOW_HELLO_WORLD} showOnlyWhenDisabled>
Sorry, toggle is off
</FeatureToggle>
</FeatureToggleProvider>
);
ReactDOM.render(<ExampleApp />, document.getElementById('example'));
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.
npm installnpm run build-exampleexample/example.html in the browsernpm run ci-build first$ claude mcp add react-feature-toggles \
-- python -m otcore.mcp_server <graph>