@scaleway/use-growthbook
Version:
Utility package to expose AB test tool
53 lines (40 loc) • 1.2 kB
Markdown
Tiny adapter to easily add [GrowthBook](https://www.growthbook.io/) to your React Application.
The idea of this package is to propose a _facade pattern_ above GrowthBook React SDK.
```bash
$ pnpm add @scaleway/use-growthbook
```
```js
import { AbTestProvider } from '@scaleway/use-growthbook'
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
ReactDOM.render(
<React.StrictMode>
<AbTestProvider
config={{ apiHost: 'string', clientKey: 'string', enableDevMode: true }}
anonymousId="123456789"
trackingCallback={(experiment, result) => console.log(experiment, result)}
errorCallback={console.error}
>
<App />
</AbTestProvider>
</React.StrictMode>,
document.getElementById('root'),
)
```
A hook `useAbTestAttributes` is available to get currentAttributes and to set new ones dynamically.
Exported utils from GrowthBook React are listed here:
- FeatureString
- FeaturesReady
- IfFeatureEnabled
- useExperiment
- useFeature
- withRunExperiment
- useFeatureIsOn
- useFeatureValue