react-awesome-feature-toggles
Advanced tools
Comparing version
{ | ||
"name": "react-awesome-feature-toggles", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Simple feature toggles for react and react router", |
@@ -25,6 +25,56 @@ [](https://travis-ci.org/Nilos/react-feature-toggles) | ||
### 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 | ||
```Javascript | ||
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 | ||
```Javascript | ||
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: | ||
```Javascript | ||
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 |
123941
1.23%80
166.67%