@@ -17,11 +17,15 @@ npm install @lectra/ld-react-feature-flags
1717```
1818
1919## Getting Started
20+
2021### FlagsProvider
21- Wrap your root component with ` FlagsProvider ` to make LaunchDarkly client instance accessible to all children components thanks to React context.
2222
23+ Wrap your root component with ` FlagsProvider ` to make LaunchDarkly client instance accessible to all children components thanks to React context.
2324
2425``` javascript
26+ // React 17 and lower
27+
28+ import ReactDOM from ' react-dom' ;
2529import { FlagsProvider } from ' @lectra/ld-react-feature-flags' ;
2630
2731ReactDOM .render (
@@ -32,6 +36,21 @@ ReactDOM.render(
3236);
3337```
3438
39+ ``` javascript
40+ // React 18 and higher
41+
42+ import { createRoot } from ' react-dom/client' ;
43+ import { FlagsProvider } from ' @lectra/ld-react-feature-flags' ;
44+
45+ const root = createRoot (document .getElementById (' root' ));
46+
47+ root .render (
48+ < FlagsProvider user= {user} clientkey= " myClientKey" loadingComponent = {< div> please wait< / div> }>
49+ < App / >
50+ < / FlagsProvider>
51+ );
52+ ```
53+
3554| Prop | Type | Required | Description |
3655| ------------------| -----------| ----------| ------------------------------|
3756| user | Object | true | User information |
@@ -40,6 +59,7 @@ ReactDOM.render(
4059| loadingComponent | Component | false | Loading component / string |
4160
4261### Flags
62+
4363All ` Flags ` components get the _ ldClient_ instance thanks to the ` FlagsProvider ` component.
4464
4565To render a node or a component based on your flags, you must pass a ` flag ` props.
@@ -121,6 +141,7 @@ import { Flags } from '@lectra/ld-react-feature-flags';
121141```
122142
123143### WithFlags
144+
124145Same as ` Flags ` components but in a Higher Order Component way.
125146
126147` WithFlags([flag])([ComponentToRenderIfTrue][ComponentToRenderIfFalse]) `
@@ -154,6 +175,7 @@ const HeaderFeatureFlipped = WithFlags("beta-only")(HBeta, HStandard)
154175
155176< HeaderFeatureFlipped>< / HeaderFeatureFlipped>
156177```
178+
157179#### Component render with multivariant flag
158180
159181``` javascript
@@ -170,6 +192,7 @@ const HeaderFeatureFlippedWithColor = WithFlags("header-bg-color")(HeaderWithCol
170192
171193
172194## Example
195+
173196This project contains some examples that you could run.
174197
175198``` bash
@@ -180,5 +203,5 @@ npm start
180203```
181204
182205## License
183- MIT
184206
207+ MIT
0 commit comments