The `launchdarkly-react-client-sdk` is the official client-side SDK for integrating LaunchDarkly feature flags into React applications. It leverages React's Context API and Hooks to provide a convenient way to access flag values and the LaunchDarkly client instance throughout a component tree. The current stable version is 3.9.0. This SDK typically sees several releases per year, often driven by updates to the underlying `js-client-sdk` and new React features. Key differentiators include its tight integration with React's component lifecycle, providing hooks like `useFlags` and `useLDClient`, and simplifying prop drilling for feature flags. It's designed for modern React development, compatible with React 16.3.0+, with Hooks requiring 16.8.0+.
npm install launchdarkly-react-client-sdkVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes the LaunchDarkly SDK using `withLDProvider`, setting up an anonymous user and then demonstrating how to retrieve flag values within a functional component using the `useFlags` hook. It includes basic error handling for a missing client-side ID.
Always use the 'Client-side ID' found in your LaunchDarkly project settings. Ensure you are not exposing server-side SDK keys in client-side code.
Verify flag settings in the LaunchDarkly dashboard. If the flag is not client-side enabled, it will always return the default value provided in your code.
Upgrade your project's `react` and `react-dom` packages to version 16.8.0 or higher. For older React versions, you must use the Higher-Order Component approach without hooks.
This change is a fix for compatibility. If you are on an older version and facing issues in older browsers with newer JS syntax, ensure your build process targets ES2015 or earlier, or upgrade to v3.3.2+.
Ensure `useFlags` and `useLDClient` are only called within functional React components. Verify `react` and `react-dom` versions are 16.8.0 or higher.
Ensure `clientSideId` is correctly passed to `withLDProvider` or `asyncWithLDProvider`, typically loaded from environment variables (e.g., `process.env.REACT_APP_LD_CLIENT_SIDE_ID`).
Ensure the SDK is fully initialized by checking `isInitialized` from the provider or by using the `waitForInitialization` option. Also, verify the flag exists and is enabled for client-side SDKs in the LaunchDarkly dashboard.