Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

launchdarkly-react-client-sdk

Package Overview
Dependencies
Maintainers
1
Versions
70
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.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
603K
increased by13.52%
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

FAQs

Package last updated on 04 Nov 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc