11# LaunchDarkly React Native SDK
22
3- :warning : UNSUPPORTED This SDK is in pre-release development and is not supported.
3+ > [ !WARNING]
4+ > UNSUPPORTED This SDK is in pre-release development and is not supported.
45
56[ ![ NPM] [ sdk-react-native-npm-badge ]] [ sdk-react-native-npm-link ]
67[ ![ Actions Status] [ sdk-react-native-ci-badge ]] [ sdk-react-native-ci ]
@@ -20,19 +21,80 @@ For more information, see the [complete reference guide for this SDK](https://do
2021yarn add @launchdarkly/react-native-client-sdk
2122```
2223
24+ Additionally, the LaunchDarkly React-Native SDK uses
25+ [ @react-native-async-storage/async-storage ] ( https://github.com/react-native-async-storage/async-storage )
26+ for bootstrapping. This is a native dependency.
27+
28+ If you are using expo, then installing this package from npm like above and re-running pod install should suffice.
29+
30+ If you are not using expo, you will need to explicitly add
31+ @react-native-async-storage/async-storage as a dependency to your project
32+ and re-run pod install for [ auto-linking to work] ( https://github.com/react-native-community/cli/issues/1347 ) .
33+
2334## Quickstart
2435
25- TODO
36+ 1 . Wrap your application with ` LDProvider ` passing it an LDClient and
37+ an LDContext:
38+
39+ ``` jsx
40+ // App.tsx
41+ import { LDProvider , ReactNativeLDClient } from ' @launchdarkly/react-native-client-sdk' ;
42+
43+ const featureClient = new ReactNativeLDClient (' mobile-key' );
44+ const userContext = { kind: ' user' , key: ' test-user-1' };
45+
46+ const App = () => (
47+ < LDProvider client= {featureClient} context= {userContext}>
48+ < Welcome / >
49+ < / LDProvider>
50+ );
51+
52+ export default App ;
53+ ```
54+
55+ 2 . Then in a child component, evaluate flags with ` useBoolVariation ` :
56+
57+ ``` jsx
58+ import { useBoolVariation } from ' @launchdarkly/react-native-client-sdk' ;
59+
60+ export default function Welcome () {
61+ const flagValue = useBoolVariation (' flag-key' , false );
2662
27- ``` typescript
28- // TODO
63+ return (
64+ < View style= {styles .container }>
65+ < Text > Welcome to LaunchDarkly< / Text >
66+ < Text > Flag value is {` ${ flagValue} ` }< / Text >
67+ < / View>
68+ );
69+ }
2970```
3071
3172See the full [ example app] ( https://github.com/launchdarkly/js-core/tree/main/packages/sdk/react-native/example ) .
3273
3374## Developing this SDK
3475
35- :information_source : See the example [ README] ( https://github.com/launchdarkly/js-core/blob/main/packages/sdk/react-native/example/README.md#L1 ) .
76+ 1 . Build all the code in the ` js-core ` repo:
77+
78+ ``` shell
79+ # at js-core repo root
80+ yarn && yarn build
81+ ```
82+
83+ 2 . The example app uses [ react-native-dotenv] ( https://github.com/goatandsheep/react-native-dotenv )
84+ to manage environment variables. Under ` packages/sdk/react-native/example `
85+ create an ` .env ` file and add your mobile key:
86+
87+ ``` shell
88+ echo " MOBILE_KEY=mob-abc" >> packages/sdk/react-native/example/.env
89+ ```
90+
91+ 3 . Run the example app. This will link the local react-native sdk code to the
92+ example app for development:
93+
94+ ``` shell
95+ # in react-native/example
96+ yarn && yarn ios-go
97+ ```
3698
3799## About LaunchDarkly
38100
0 commit comments