Set up React Native SDK

LaunchDarkly onboarding is not available in federal environments
To learn more, read LaunchDarkly in federal environments.

Install the package

$yarn add @launchdarkly/react-native-client-sdk

LaunchDarkly’s React Native SDK v10 uses @react-native-async-storage/async-storage for bootstrapping. If you are not using Expo, you must explicitly add it as a dependency.

$yarn add @react-native-async-storage/async-storage

Initialize the SDK

React Native SDK initialization
1import {
2 AutoEnvAttributes,
3 LDProvider,
4 ReactNativeLDClient,
5} from '@launchdarkly/react-native-client-sdk';
6
7// This is your mobile key.
8const ldClient = new ReactNativeLDClient('YOUR_MOBILE_KEY', AutoEnvAttributes.Enabled, {
9 debug: true,
10 applicationInfo: {
11 id: 'ld-rn-test-app',
12 version: '0.0.1',
13 },
14});
15
16// A "context" is a data object representing users, devices, organizations, and other entities.
17const context = { kind: 'user', key: 'EXAMPLE_CONTEXT_KEY' };
18
19const App = () => {
20 useEffect(() => {
21 ldClient.identify(context);
22 }, []);
23
24 return (
25 <LDProvider client={ldClient}>
26 <YourComponent />
27 </LDProvider>
28 );
29};
30
31export default App;

You can find your server-side SDK key, client-side ID, and mobile key in the “Resources” section of the help menu. Click the help icon at the bottom left corner of the LaunchDarkly UI, then choose SDK keys:

The SDK keys option in the help menu.

The SDK keys option in the help menu.

To learn more, read Initialize the client and identify a context in the React Native SDK reference guide.