You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-16Lines changed: 31 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,37 +29,52 @@ class MyComponent extends Component {
29
29
}
30
30
```
31
31
32
-
The component will receive a prop named `toggles` with an array of toggles, similar to this:
32
+
The component will receive a prop named `toggles` with an array of toggles. You are free to implement any object pattern with the information needed to implement your toggle. This may be the simplest configuration possible to activate a simple toggle:
33
33
34
34
```javascript
35
35
[{
36
36
myToggle:true
37
-
}, {
38
-
myDisabledToggle:false
39
-
}, {
40
-
yetAnotherToggle:true
41
37
}]
42
38
```
43
39
40
+
Just keep in mind to be consistent when implementing the feature toggle in your component, and with the object you are sending in the array of toggles.
41
+
44
42
In the previous example, the component will only make use of `myToggle`... But how does it receive it? This is where `react-feature-toggles` is useful.
45
43
46
-
First, wrap your component into the higher order component `ReactToggle`:
44
+
React Feature Toggles provides you two HOC: `ToggleApp` and `ToggleComponent`. Let's examine them in detail:
45
+
46
+
## ToggleComponent
47
+
At the component level, just wrap your component into the higher order component `ToggleComponent`:
This will export your component as a _toggleable_ component.
55
+
This will export your component as a _toggled_ component. What does it mean? Just that it will be wrapped with a Higher Order Component that will receive by context an array of toggles and pass it as props to your component.
56
+
57
+
Please notice that you only need to wrap your toggled component with the `ToggleComponent`, not the rest of your application's components, and the organic components using it neither. Please review the `docs` folder for a full example.
55
58
56
-
Secondly, the user of your component will need to provide the toggles somehow. It's up to you how to decide which toggles are activated or not, but you must provide the component a `promise` property with a `Promise` function that returns an array of feature toggles on being fullfilled:
59
+
## ToggleApp
60
+
At the top level of your application, you must wrap your app with the higher order component `ToggleApp`:
57
61
58
62
```javascript
59
-
ReactDom.render(<MyComponent promise={
60
-
newPromise(resolve=> {
61
-
resolve([{myToggle:true}]);
62
-
})
63
-
}
64
-
/>, document.getElementById('main'));
63
+
import { ToggleApp } from'react-feature-toggle';
64
+
...
65
+
constMyToggledApp=ToggleApp(MyApp, toggles);
65
66
```
67
+
68
+
The way to provide the array of toggles is up to you, but keep in mind that the user of your app will need to provide the toggles somehow. In the following example, I'm providing a `Promise` function that returns an array of feature toggles on being fullfilled:
0 commit comments