Documentation Index
Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
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.
Overview
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:
| Resource | Location |
|---|---|
| SDK API documentation | SDK API docs |
| Supported SDK Versions | React Native SDK |
| GitHub repository | react-native |
| Sample Expo application | React Native |
| Published module | npm |
Get started
After you complete the Get started process, follow these instructions to start using the LaunchDarkly SDK in your React Native code:Understand version compatibility
The following table describes the LaunchDarkly React Native SDK version compatibility: | LaunchDarkly React Native SDK version| Compatible with |
|---|
Install the SDK
To install the SDK:- Install the LaunchDarkly SDK as a dependency.
- The LaunchDarkly React Native SDK version 10 uses
@react-native-async-storage/async-storagefor 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-storageas a dependency to your project.
-
Run
npx pod-install. - Next, import the SDK into your project:
-
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 toLDProvider.LDProvideruses the React context API to store and pass data to child components through hooks. It requires the client.
Initialize the client and identify a context
In version 10 of the SDK, you do not specify a context when you initialize the client. Instead, you must provide the context in anidentify() 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().
The following example shows the simplest way to create a shared instance of ReactNativeLDClient, and identify a context:
LDOptions.
Background fetch
In version 10, the React Native SDK defaults to astreaming 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
Shut down the client when your application terminates. To learn more, read Shutting down.Data collection
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.Troubleshooting
If your application logs show the errorLaunchDarklyFlagFetchError: 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”.
Supported features
This SDK supports the following features:- Anonymous contexts and users
- Automatic environment attributes
- Configuration, including
- Context configuration
- Evaluating flags
- Flag evaluation reasons
- Flushing events
- Getting all flags
- Hooks
- Identifying and changing contexts
- Logging
- Monitoring SDK status
- Multiple environments
- Observability
- Offline mode
- OpenTelemetry in client-side SDKs
- Private attributes
- Relay Proxy configuration, using proxy mode
- Sending custom events
- Shutting down
- Subscribing to flag changes