# launchdarkly-context-provider

> Context Provider for Launch Darkly

Latest version **1.0.0** (published 2023-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install launchdarkly-context-provider
pnpm add launchdarkly-context-provider
yarn add launchdarkly-context-provider
bun add launchdarkly-context-provider
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-11-04 |
| First published | 2023-11-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Marcelo Origoni |
| Maintainers | marcelo.origoni |
| Keywords | LaunchDarkly, LaunchDarkly Context, LaunchDarkly Context Provider |

## Links

- npm: https://www.npmjs.com/package/launchdarkly-context-provider
- Repository: https://github.com/marceloOrigoni/launchdarkly-context-provider
- Homepage: https://github.com/marceloOrigoni/launchdarkly-context-provider#readme
- Issues: https://github.com/marceloOrigoni/launchdarkly-context-provider/issues
- npm.io page: https://npm.io/package/launchdarkly-context-provider

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-11-04

## README

# `LaunchDarklyProvider` Component

The `LaunchDarklyProvider` is a React component that is designed to work with the LaunchDarkly feature flag management system. It initializes the LaunchDarkly client, retrieves feature flags, and provides them to its child components via a context. The component also handles cleanup when it's unmounted.

## Using `LaunchDarklyProvider` Component

To integrate the `LaunchDarklyProvider` component into your React application, follow these steps:

### 1. Import Dependencies

First, make sure you've imported the necessary dependencies and custom modules in your React file:

```javascript
import React from 'react';
import { LaunchDarklyProvider } from 'launchdarkly-context-provider'
```

### 2. Define User Context and Feature Flags

Define the user context and initial feature flags you want to use within your application. The user context typically includes a unique user key:

```javascript
const userContext = {
  key: 'unique_user_key',
  // Add other user context properties as needed
};

const initialFeatureFlags = {
  featureFlag1: false,
  featureFlag2: true,
  // Add other feature flags as needed
};
```

### 3. Wrap Your Application with `LaunchDarklyProvider`

Wrap your application or a specific part of it with the `LaunchDarklyProvider`. Provide the required props:

- `launchDarklyClientSideId`: Your LaunchDarkly client-side ID.
- `launchDarklyUserContext`: The user context you defined in step 2.
- `launchDarklyFeatureFlags`: The initial feature flags you defined in step 2.

```javascript
function App() {
  return (
    <LaunchDarklyProvider
      launchDarklyClientSideId="YOUR_CLIENT_SIDE_ID"
      launchDarklyUserContext={userContext}
      launchDarklyFeatureFlags={initialFeatureFlags}
    >
      {/* Your application components go here */}
    </LaunchDarklyProvider>
  );
}
```

### 4. Access Feature Flags in Your Components

Within your application components, you can access the feature flags provided by the `LaunchDarklyProvider` by using the `useLaunchDarkly` hook.

First, import the `useLaunchDarkly` hook:

```javascript
import { useLaunchDarkly } from 'launchdarkly-context-provider'
```

Then, use the `useLaunchDarkly` hook to access the feature flags:

```javascript
function MyFeatureComponent() {
  const featureFlags = useLaunchDarkly();

  // Access individual feature flags as needed
  const isFeatureFlag1Enabled = featureFlags.featureFlag1;
  const isFeatureFlag2Enabled = featureFlags.featureFlag2;

  // Render your component based on feature flag values
  // ...
}
```

Now your components can make decisions and render content based on the state of your feature flags.

---
_Source: https://npm.io/package/launchdarkly-context-provider · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
