Skip to main content

SDK Quickstart

Get GrowthBook running in your application in minutes.

New to GrowthBook SDKs?

The SDK Overview covers how SDKs work and helps you choose the right one for your use case.

1

Get your SDK Client Key

Go to SDK Configuration, create a new SDK Connection, and copy the Client Key (starts with sdk-).

1

Install the SDK

npm install @growthbook/growthbook-react @growthbook/growthbook
1

Wrap your app with GrowthBookProvider

import { GrowthBook, GrowthBookProvider } from "@growthbook/growthbook-react";
import { thirdPartyTrackingPlugin, autoAttributesPlugin } from "@growthbook/growthbook/plugins";

// Create a GrowthBook instance
const gb = new GrowthBook({
apiHost: "https://cdn.growthbook.io",
clientKey: "sdk-abc123", // Your SDK client key
enableDevMode: true,
plugins: [
thirdPartyTrackingPlugin(), // Optional, sends "Experiment Viewed" events via GrowthBook Managed Warehouse, Google Analytics, Google Tag Manager, and Segment.
autoAttributesPlugin(), // Optional, sets common attributes (browser, session_id, etc.)
],
});

// Load feature definitions from the GrowthBook API
gb.init();

export default function App() {
return (
<GrowthBookProvider growthbook={gb}>
<MyApp />
</GrowthBookProvider>
);
}
1

Use feature flags

import { useFeatureIsOn, useFeatureValue } from "@growthbook/growthbook-react";

function MyApp() {
const showNewFeature = useFeatureIsOn("new-feature");
const buttonColor = useFeatureValue("button-color", "blue");

return (
<div>
{showNewFeature && <NewFeature />}
<button style={{ backgroundColor: buttonColor }}>Click me</button>
</div>
);
}

Next steps: - See the example Next.js app - See the React SDK docs


Verify your setup

After setting up your SDK, verify it's working by following these steps:

  1. Create a feature flag called test-flag in your GrowthBook
  2. Set its value to true and enable it for your environment
  3. Check that isOn("test-flag") returns true in your app
  4. Toggle the flag off and verify the change is reflected
tip

Use the GrowthBook DevTools browser extension to inspect and test feature flags in development.