> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up React Native SDK

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

<View title="Federal docs">
  <Danger>
    **LaunchDarkly onboarding is not available in federal environments**

    To learn more, read <a href="/docs/home/infrastructure/federal">LaunchDarkly in federal environments</a>.
  </Danger>
</View>

Install and initialize the LaunchDarkly React Native SDK to start evaluating feature flags in your application.

## Install the package

<CodeGroup>
  ```shell title="yarn" lines wrap theme={null}
  yarn add @launchdarkly/react-native-client-sdk
  ```

  ```shell title="npm" lines wrap theme={null}
  npm i @launchdarkly/react-native-client-sdk
  ```

  ```shell title="pnpm" lines wrap theme={null}
  pnpm i @launchdarkly/react-native-client-sdk
  ```
</CodeGroup>

LaunchDarkly's React Native SDK v10 uses [@react-native-async-storage/async-storage](https://github.com/react-native-async-storage/async-storage) for bootstrapping. If you are not using Expo, you must explicitly add it as a dependency.

<CodeGroup>
  ```shell title="yarn" lines wrap theme={null}
  yarn add @react-native-async-storage/async-storage
  ```

  ```shell title="npm" lines wrap theme={null}
  npm i @react-native-async-storage/async-storage
  ```

  ```shell title="pnpm" lines wrap theme={null}
  pnpm i @react-native-async-storage/async-storage
  ```
</CodeGroup>

### Initialize the SDK

```tsx title="React Native SDK initialization" expandable lines wrap theme={null}
import {
  AutoEnvAttributes,
  LDProvider,
  ReactNativeLDClient,
} from '@launchdarkly/react-native-client-sdk';

// This is your mobile key.
const ldClient = new ReactNativeLDClient('YOUR_MOBILE_KEY', AutoEnvAttributes.Enabled, {
  debug: true,
  applicationInfo: {
    id: 'ld-rn-test-app',
    version: '0.0.1',
  },
});

// A "context" is a data object representing users, devices, organizations, and other entities.
const context = { kind: 'user', key: 'EXAMPLE_CONTEXT_KEY' };

const App = () => {
  useEffect(() => {
    ldClient.identify(context);
  }, []);

  return (
    <LDProvider client={ldClient}>
      <YourComponent />
    </LDProvider>
  );
};

export default App;
```

### Initialize the SDK for feature management and Experimentation

If you want to use the LaunchDarkly [Experimentation](/docs/home/experimentation) feature, include a track call in your initialization code:

```ts title="React Native SDK initialization for Experimentation" expandable lines wrap theme={null}
import React, { useEffect, useState, useCallback } from 'react';
import {
  AutoEnvAttributes,
  LDProvider,
  ReactNativeLDClient,
} from '@launchdarkly/react-native-client-sdk';

// This is your mobile key.
const ldClient = new ReactNativeLDClient('YOUR_MOBILE_KEY', AutoEnvAttributes.Enabled, {
  debug: true,
  applicationInfo: {
    id: 'ld-rn-test-app',
    version: '0.0.1',
  },
});

// A "context" is a data object representing users, devices, organizations, and other entities.
const context = { kind: 'user', key: 'EXAMPLE_CONTEXT_KEY', email: 'EXAMPLE_EMAIL' };

export default function App() {
  const [ready, setReady] = useState<boolean>(false);
  // Wait for identify to complete before rendering, so no flag evaluates
  // against defaults during startup.
  useEffect(() => {
    (async () => {
      await ldClient.identify(context);
      setReady(true);
    })();
  }, []);
  // Call trackMetric when a metric action occurs in your app —
  // a tap, a form submit, a screen view, a custom event, whatever your metric measures.
  const trackMetric = useCallback(
    (metricKey: string, data?: unknown) => {
      ldClient.track(metricKey, data);
    },
    [],
  );
  if (!ready) return null;
  return (
    <LDProvider client={ldClient}>
      <YourComponent />
    </LDProvider>
  );
}
```

<Accordion title="Finding your SDK credentials">
  You can find your server-side SDK keys, mobile keys, and client-side ID on the **SDK keys** page under **Settings**.
</Accordion>

To learn more, read [Initialize the client and identify a context](/docs/sdk/client-side/react/react-native#initialize-the-client-and-identify-a-context) in the React Native SDK reference guide.
