Version 10 of the React Native SDK has been rewritten in pure TypeScript and is compatible with Expo. Only iOS and Android platforms are supported. Web is not supported. Version 10 is a rewrite of the React Native SDK. It is based on the JavaScript SDK, and it replaces launchdarkly-react-native-client-sdk. To learn more about upgrading, read React Native SDK 9.x to 10.0 migration guide.
This topic documents how to get started with the React Native SDK, and links to reference information on all of the supported features.
LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and sample applications:
After you complete the Get started process, follow these instructions to start using the LaunchDarkly SDK in your React Native code:
The LaunchDarkly React Native client-side SDK version 10.x is compatible with Expo. Only iOS and Android platforms are supported. Web is not supported.
Earlier versions of the LaunchDarkly React Native SDK are not compatible with the Expo managed workflow because they use native modules. Consider upgrading to the 10.x version of the LaunchDarkly SDK, or using the bare workflow instead.
The following table describes the LaunchDarkly React Native SDK version compatibility:
To learn more, read Releases.
To install the SDK:
We recommend making the LaunchDarkly observability plugin available as well. This plugin collects and sends observability data to LaunchDarkly. This means you can review error monitoring and logs from within the LaunchDarkly UI. It requires the React Native SDK version 10.10 or later.
Here’s how:
@react-native-async-storage/async-storage for bootstrapping:If you are using Expo, skip this step and continue to step 3.
If you are not using Expo, you must explicitly add @react-native-async-storage/async-storage as a dependency to your project.
Run npx pod-install.
Next, import the SDK into your project:
The React Native SDK uses a mobile key. Keys are specific to each project and environment. They are available on the SDK keys page under Settings. To learn more about key types, read Keys.
Mobile keys are not secret and you can expose them in your client-side code without risk. However, never embed a server-side SDK key into a client-side application.
After the SDK is imported, create a single, shared instance of ReactNativeLDClient. To create this, you need your environment’s mobile key. This authorizes your application to connect to a particular environment within LaunchDarkly.
After you instantiate ReactNativeLDClient, pass it to LDProvider. LDProvider uses the React context API to store and pass data to child components through hooks. It requires the client.
In version 10 of the SDK, you do not specify a context when you initialize the client. Instead, you must provide the context in an identify() call, for example on application mount. The identify() method returns a promise that can be awaited. End users will receive fallback values until you specify a context by calling identify().
Do not configure your SDK to initialize without a timeout parameter. Doing so will cause your app never to load if there is a connectivity problem. We recommend setting a timeout for no more than 1-5 seconds.
In v10, the identify timeout defaults to 5 seconds. In older versions, the client.configure takes a timeout parameter.
The following example shows the simplest way to create a shared instance of ReactNativeLDClient, and identify a context:
To learn more about the specific configuration options available in this SDK, read LDOptions.
We recommend making ReactNativeLDClient a singleton for each LaunchDarkly project. The client instance maintains internal state that allows LaunchDarkly to serve feature flags without making any remote requests.
You must make feature flags available to mobile SDKs before the SDK can evaluate those flags. If an SDK tries to evaluate a feature flag that is not available, LaunchDarkly serves the fallback value for that flag.
To make a flag available to this SDK, check the SDKs using Mobile key checkbox during flag creation, or toggle on the option in the flag’s right sidebar. To make all of a project’s flags available to this SDK by default, check the SDKs using Mobile key checkbox on your project’s Flag settings page.
In version 10, the React Native SDK defaults to a streaming connection mode. In this mode, your application receives updates when it is in the foreground and does not when it is in the background. To learn more, read Offline mode.
In previous versions, the SDK defaulted to the background fetch behavior for the platform it was running on.
Shut down the client when your application terminates. To learn more, read Shutting down.
To learn more about data collection within this SDK and implications on submissions to the Apple App Store, read Apple App Store data collection policy.
If your application logs show the error LaunchDarklyFlagFetchError: network error, it may indicate a problem with network connectivity between your SDK and LaunchDarkly.
For steps to resolve this issue, read the LaunchDarkly Knowledge Base article Error “LaunchDarklyFlagFetchError: network error”.
This SDK supports the following features: