# react-featureflow-client

> React Library wrapper for the featureflow javascript SDK

Latest version **2.6.0** (published 2026-08-30) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install react-featureflow-client
pnpm add react-featureflow-client
yarn add react-featureflow-client
bun add react-featureflow-client
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.6.0 |
| Published | 2026-08-30 |
| First published | 2017-03-30 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 73.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Featureflow Pty. Ltd. |
| Maintainers | henry.r.t.young, oliverfeatureflow |
| Keywords | react, feature flags, featureflow, featureflow-client |

## Links

- npm: https://www.npmjs.com/package/react-featureflow-client
- Repository: https://github.com/featureflow/react-featureflow-client
- Homepage: https://github.com/featureflow/react-featureflow-client#readme
- Issues: https://github.com/featureflow/react-featureflow-client/issues
- npm.io page: https://npm.io/package/react-featureflow-client

## Dependencies (1)

- [featureflow-client](https://npm.io/package/featureflow-client.md) 2.6.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.6.0 (latest) — 2026-08-30
- 2.2.0-beta.1 (beta) — 2026-07-24
- 2.5.0 — 2026-08-21
- 2.4.1 — 2026-08-20
- 2.4.0 — 2026-08-20
- 2.3.0 — 2026-08-12
- 2.2.1 — 2026-07-28
- 2.2.0 — 2026-07-26
- 2.1.0 — 2025-12-02
- 2.1.0-beta.7 — 2025-12-02
- 2.1.0-beta.6 — 2025-11-18
- 2.1.0-beta.5 — 2025-11-17
- 2.1.0-beta.4 — 2025-11-17
- 2.1.0-beta.3 — 2025-11-17
- 2.1.0-beta.2 — 2025-11-17
- … 56 more at https://npm.io/package/react-featureflow-client/versions

## README

# react-featureflow-client

[![][npm-img]][npm-url]

> Official React bindings for [Featureflow Javascript Client](https://github.com/featureflow/featureflow-javascript-sdk)

Get your Featureflow account at [featureflow.io](http://www.featureflow.io)

## Installation

```bash
npm install react-featureflow-client
```

## Quick Start

### 1. Initialize the Provider (Recommended: Async)

The `asyncFeatureflowProvider` initializes Featureflow **before** your app renders, ensuring features are available immediately with no flicker.

```tsx
// index.tsx
import React from 'react';
import ReactDOM from 'react-dom';
import { asyncFeatureflowProvider } from 'react-featureflow-client';
import App from './App';

const FF_KEY = 'js-env-YOUR_KEY_HERE';
const user = {
  id: 'user-123',
  attributes: {
    tier: 'gold',
    country: 'australia'
  }
};

const initApp = async () => {
  const FeatureflowProvider = await asyncFeatureflowProvider({
    apiKey: FF_KEY,
    user
  });

  ReactDOM.render(
    <FeatureflowProvider>
      <App />
    </FeatureflowProvider>,
    document.getElementById('root')
  );
};

initApp();
```

### 2. Use Feature Flags in Components

```tsx
// App.tsx
import React from 'react';
import { useFeatureflow, useFeatures } from 'react-featureflow-client';

function App() {
  const featureflow = useFeatureflow();
  const features = useFeatures();

  const isNewUIEnabled = featureflow.evaluate('new-ui').isOn();

  return (
    <div>
      {isNewUIEnabled ? <NewUI /> : <OldUI />}
      
      {/* Display all features */}
      <ul>
        {Object.entries(features).map(([key, value]) => (
          <li key={key}>{key}: {value}</li>
        ))}
      </ul>
    </div>
  );
}
```

## Provider Options

### `asyncFeatureflowProvider` (Recommended)

Initializes the client **before** React renders. No flicker, features available immediately.

```tsx
const FeatureflowProvider = await asyncFeatureflowProvider({
  apiKey: 'js-env-YOUR_KEY',
  user: { id: 'user-123', attributes: { plan: 'premium' } },
  config: { offline: false }  // optional
});
```

### `FeatureflowProvider` (Standard)

Initializes the client **after** mount in `useEffect`. Simpler setup, but may cause brief flicker.

```tsx
import { FeatureflowProvider } from 'react-featureflow-client';

<FeatureflowProvider
  apiKey="js-env-YOUR_KEY"
  user={{ id: 'user-123', attributes: { plan: 'premium' } }}
  config={{ offline: false }}
>
  <App />
</FeatureflowProvider>
```

### `FeatureflowProviderWithClient` (Bring Your Own Client)

Use an existing Featureflow client instance:

```tsx
import Featureflow from 'featureflow-client';
import { FeatureflowProviderWithClient } from 'react-featureflow-client';

const client = await Featureflow.init('js-env-YOUR_KEY', user);

<FeatureflowProviderWithClient client={client}>
  <App />
</FeatureflowProviderWithClient>
```

## Hooks

### `useFeatureflow()`

Returns the Featureflow client instance for evaluating features and tracking goals.

```tsx
const featureflow = useFeatureflow();

// Evaluate a feature
const isOn = featureflow.evaluate('my-feature').isOn();
const variant = featureflow.evaluate('my-feature').value();

// Check specific variant
const isPremium = featureflow.evaluate('pricing-tier').is('premium');
```

### `useFeatures()`

Returns all evaluated features as an object. Automatically updates when features change.

```tsx
const features = useFeatures();

// features = { 'feature-a': 'on', 'feature-b': 'variant-1', ... }
```

### `useFeature(key)`

Evaluates a single feature and returns the full `Evaluate` object
(`value()`/`is()`/`isOn()`/`isOff()`/`jsonValue()`). Re-evaluates automatically when
features update.

```tsx
const feature = useFeature('my-feature');

if (feature.isOn()) {
  // ...
}
```

### `useJsonValue(key)`

Returns the evaluated variant's JSON config payload directly, or `undefined` if the
variant has none.

```tsx
const config = useJsonValue<{ color: string }>('my-feature');
```

### `useTrack()`

Returns a stable function for tracking goal events for the current user. The optional
`details` argument is a number (the metric value) or an object whose optional `value` is
the metric value and whose remaining properties are sent as custom data.

```tsx
const track = useTrack();

track('button-clicked');
track('purchase', 49.95);
track('purchase', { value: 49.95, plan: 'pro' });
```

## Updating User Context

Update the user context at runtime to re-evaluate features (e.g., after login):

```tsx
const featureflow = useFeatureflow();

// Update user and re-evaluate all features
await featureflow.updateUser({
  id: 'new-user-id',
  attributes: {
    tier: 'premium',
    beta: true
  }
});
```

## TypeScript Support

The package includes TypeScript definitions. Import types as needed:

```tsx
import type { 
  FeatureflowUser, 
  FeatureflowClient,
  Config,
  EvaluatedFeatures 
} from 'react-featureflow-client';
```

## Example App

Run the included example:

```bash
cd example
yarn install
yarn start
```

The example demonstrates:
- Switching between async and standard providers
- Editing user context at runtime
- Feature flag evaluation with hooks

## API Reference

### Exports

| Export | Type | Description |
|--------|------|-------------|
| `asyncFeatureflowProvider` | Function | Async function returning a provider component |
| `FeatureflowProvider` | Component | Standard provider component |
| `FeatureflowProviderWithClient` | Component | Provider accepting an existing client |
| `useFeatureflow` | Hook | Returns the Featureflow client |
| `useFeatures` | Hook | Returns evaluated features object |

### Provider Props

| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `apiKey` | `string` | Yes | Your Featureflow JS environment SDK key |
| `user` | `FeatureflowUser` | No | User context for targeting |
| `config` | `Config` | No | Client configuration options |

### FeatureflowUser

```tsx
interface FeatureflowUser {
  id: string;
  attributes?: {
    [key: string]: string | number | boolean | string[];
  };
}
```

## Migration from v1.x

Version 2.x uses the React Context API and requires React 16.3+.

**Key changes:**
- Use `asyncFeatureflowProvider` or `FeatureflowProvider` instead of `withFeatureflowProvider`
- Use `useFeatureflow()` and `useFeatures()` hooks instead of HOCs
- The `featureflow-client` SDK is now bundled (no separate install needed)

## License

Apache-2.0

[npm-url]: https://nodei.co/npm/react-featureflow-client
[npm-img]: https://nodei.co/npm/react-featureflow-client.png

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