# @wisersolutions/launchdarkly-react

> LaunchDarkly SDK wrappers and associated utilities to provide a modern API and enforce best practices.

Latest version **0.0.3** (published 2021-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @wisersolutions/launchdarkly-react
pnpm add @wisersolutions/launchdarkly-react
yarn add @wisersolutions/launchdarkly-react
bun add @wisersolutions/launchdarkly-react
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2021-01-20 |
| First published | 2020-10-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Wiser Solutions, Inc. |
| Maintainers | hon2a, mcarlotta |

## Links

- npm: https://www.npmjs.com/package/@wisersolutions/launchdarkly-react
- Repository: https://github.com/WiserSolutions/launchdarkly
- Homepage: https://github.com/WiserSolutions/launchdarkly#readme
- Issues: https://github.com/WiserSolutions/launchdarkly/issues
- npm.io page: https://npm.io/package/@wisersolutions/launchdarkly-react

## Dependencies (5)

- [react](https://npm.io/package/react.md) >=16.8
- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [core-js](https://npm.io/package/core-js.md) ^3.4.5
- [@babel/runtime-corejs3](https://npm.io/package/@babel/runtime-corejs3.md) ^7.7.4
- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) ^2.18.2

## Recent versions

- 0.0.3 (latest) — 2021-01-20
- 0.0.2 — 2020-10-22
- 0.0.1 — 2020-10-22

## README

# launchdarkly-react

[LaunchDarkly SDK](https://docs.launchdarkly.com/sdk/client-side/javascript) wrapper for React intended to provide
a modern API and enforce best practices.

## Use

Connect to LaunchDarkly with the `useLaunchDarklyClient` hook and provide the client through context to your app:

```javascript
import { useLaunchDarklyClient, FeatureFlagsProvider } from '@wisersolutions/launchdarkly'

const App = props => {
  // get `clientKey` and `user` either from `props` or fetch them here with hooks

  // same arguments as `initialize()` from `launchdarkly-js-client-sdk`
  const launchDarklyClient = useLaunchDarklyClient(clientKey, user, options)

  return (
    <FeatureFlagsProvider value={launchDarklyClient}>
      {/* app content */}
    </FeatureFlagsProvider>
  )
}
```

Then use `useFeatureFlag(flagKey: string, defaultValue?: any): any` anywhere in your app to get feature flag variation
and subscribe to changes:

```javascript
import { useFeatureFlag } from '@wisersolutions/launchdarkly'

const Component = props => {
  const showFeature = useFeatureFlag('some-boolean-flag-key')
  const otherFeatureVariation = useFeatureFlag('some-multi-variation-flag-key', 'A')
  
  return showFeature ? (
    <Container>
      {{
        A: 'content for variant A',
        B: <div>other content for variant B</div>,
        C: null // no content for variant C
      }[otherFeatureVariation]}
    </Container>
  ) : null
}
```

See [SDK docs](https://docs.launchdarkly.com/sdk/client-side/javascript) for argument details.

## Development

### Install

Install dependencies using:

```sh
npm install
```

### Develop

After you modify sources, run the following (or set up your IDE to do it for you):

- format the code using `npm run format`
- lint it using `npm run lint`
- test it using `npm test`

and fix the errors, if there are any.

### Publish

Publishing is done in two steps:

1. Create a new version tag and push it to the repository:
    ```sh
    npm version <patch|minor|major>
    git push --follow-tags
    ```
1. Build and publish the new version as a npm package:
    ```sh
    npm publish --access public
    ```

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