You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

launchdarkly-react-client-sdk

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

launchdarkly-react-client-sdk

LaunchDarkly SDK for React

3.8.0
Source
npmnpm
Version published
Weekly downloads
848K
3.82%
Maintainers
1
Weekly downloads
 
Created

What is launchdarkly-react-client-sdk?

The launchdarkly-react-client-sdk is a client-side SDK for integrating LaunchDarkly's feature flagging and experimentation capabilities into React applications. It allows developers to control feature releases, perform A/B testing, and manage feature flags in real-time.

What are launchdarkly-react-client-sdk's main functionalities?

Initialize the SDK

This code demonstrates how to initialize the LaunchDarkly SDK in a React application using the `withLDProvider` higher-order component. Replace 'YOUR_CLIENT_SIDE_ID' with your actual LaunchDarkly client-side ID.

import { withLDProvider } from 'launchdarkly-react-client-sdk';

const App = () => (
  <div>
    <h1>My App</h1>
  </div>
);

export default withLDProvider({
  clientSideID: 'YOUR_CLIENT_SIDE_ID'
})(App);

Use feature flags

This code demonstrates how to use feature flags in a React component with the `useFlags` hook. The `myFeatureFlag` variable will be `true` or `false` based on the feature flag's state in LaunchDarkly.

import { useFlags } from 'launchdarkly-react-client-sdk';

const MyComponent = () => {
  const { myFeatureFlag } = useFlags();

  return (
    <div>
      {myFeatureFlag ? <p>Feature is enabled</p> : <p>Feature is disabled</p>}
    </div>
  );
};

Track custom events

This code demonstrates how to track custom events using the `useLDClient` hook. The `ldClient.track` method sends a custom event to LaunchDarkly, which can be used for analytics and experimentation.

import { useLDClient } from 'launchdarkly-react-client-sdk';

const MyComponent = () => {
  const ldClient = useLDClient();

  const handleClick = () => {
    ldClient.track('button-clicked', { customData: 'example' });
  };

  return (
    <button onClick={handleClick}>Click me</button>
  );
};

Other packages similar to launchdarkly-react-client-sdk

Keywords

launchdarkly

FAQs

Package last updated on 29 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts