> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up React Web SDK

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

<View title="Federal docs">
  <Danger>
    **LaunchDarkly onboarding is not available in federal environments**

    To learn more, read <a href="/docs/home/infrastructure/federal">LaunchDarkly in federal environments</a>.
  </Danger>
</View>

Install and initialize the LaunchDarkly React Web SDK to start evaluating feature flags in your application.

## Install the package

<CodeGroup>
  ```shell title="yarn" lines wrap theme={null}
  yarn add @launchdarkly/react-sdk
  ```

  ```shell title="npm" lines wrap theme={null}
  npm i @launchdarkly/react-sdk
  ```

  ```shell title="pnpm" lines wrap theme={null}
  pnpm i @launchdarkly/react-sdk
  ```
</CodeGroup>

### Initialize the SDK for feature management

```tsx title="React Web SDK initialization" expandable lines wrap theme={null}
// Add the code below to the root of your React app.
import { createRoot } from 'react-dom/client';
import { createLDReactProvider, LDContext } from '@launchdarkly/react-sdk';

function App() {
  return <div>Let your feature flags fly!</div>
}

// A "context" is a data object representing users, devices, organizations, and other entities.
const context: LDContext = {
  kind: 'user',
  key: 'EXAMPLE_CONTEXT_KEY',
  email: 'biz@face.dev',
};

// This is your client-side ID.
const LDReactProvider = createLDReactProvider('YOUR_CLIENT_SIDE_ID', context);

createRoot(document.getElementById('root') as HTMLElement).render(
  <LDReactProvider>
    <App />
  </LDReactProvider>,
);
```

### Initialize the SDK for feature management and Experimentation

If you want to use the LaunchDarkly [Experimentation](/docs/home/experimentation) feature, include a track call in your initialization code:

```ts title="React Web SDK initialization for Experimentation" expandable lines wrap theme={null}
// Add the code below to the root of your React app.
import { StrictMode, useCallback } from 'react';
import { createRoot } from 'react-dom/client';
import { createLDReactProvider, useLDClient } from '@launchdarkly/react-sdk';

function App() {
  const ldClient = useLDClient();
  // Call trackMetric when a metric action occurs in your app —
  // a click, a form submit, a page view, a custom event, whatever your metric measures.
  const trackMetric = useCallback(
    (metricKey: string, data?: unknown) => {
      ldClient?.track(metricKey, data);
    },
    [ldClient],
  );
  return <div>Let your feature flags fly!</div>;
}

// A "context" is a data object representing users, devices, organizations, and other entities.
const context = {
  kind: 'user',
  key: 'EXAMPLE_CONTEXT_KEY',
  email: 'EXAMPLE_EMAIL',
};

// Initialize the SDK so flag values are ready before your app renders.
// This is your client-side ID.
const LDProvider = createLDReactProvider('YOUR_CLIENT_SIDE_ID', context);

createRoot(document.getElementById('root') as HTMLElement).render(
  <StrictMode>
    <LDProvider>
      <App />
    </LDProvider>
  </StrictMode>,
);
```

<Accordion title="Finding your SDK credentials">
  You can find your server-side SDK keys, mobile keys, and client-side ID on the **SDK keys** page under **Settings**.
</Accordion>

To learn more, read [Initialize the client](/docs/sdk/client-side/react/react-web#initialize-the-client) in the React Web SDK reference guide.
