Link Search Menu Expand Document


This page explains how to add AppFlags to a React application.

Add the SDK to your project

Install the appflags-react npm package and save it to your package.json file:

npm install appflags-react --save

Initialize the client

When to initialize

You should initialize the AppFlags client as soon as your application launches. The client initialization is async and will not block your application from loading.

The AppFlags client makes a request to our servers to initialize, which takes around 100ms. Initializing the client when the application launches ensures that you can utilize feature flags without any noticeable delay to your users.

Providing a user key

You need to provide a unique key for the user when initializing the AppFlags client. You should use an identifier that will not change, like an account ID or email address.

The AppFlags client determines which variation a user receives based on their key, so it is important that each user has a unique and unchanging key.

Client key

The AppFlags client is initialized with a client key, which configures the client for the appropriate environment in your account. For more information see SDK client keys.

Each environment (e.g. production or staging) in your account has a different client key. Ensure you are using the correct client key corresponding to your application’s environment.

Code sample

const user = {
    key: "UNIQUE_USER_KEY"  // e.g. email, account id, etc
AppFlags.initialize("YOUR_CLIENT_KEY", user);

© 2020 AppFlags