React SDK
What is the React SDK?
The React SDK is an open-source client-side Typescript/JavaScript library that allows you to integrate Bucket with your app.
It also works out of the box with Next.js.
Getting started
You can find the full developer documentation on GitHub.
Install the SDK
Install the SDK.
Define your features
To get type safe feature definitions, extend the definition of the Features
interface and define which features you have. See the example below for the details.
If no explicit feature definitions are provided, there will be no types checked feature lookups.
Example
Add the context provider
Add the BucketProvider
context provider to your application. This will initialize the Bucket SDK to fetch feature configuration and listen for automated feedback survey events.
Once a features has been successfully fetched, they are stored in localStorage
and will be used as a fallback for up to 30 days if the client cannot connect to Bucket's servers.
publishableKey
is used to connect the provider to an environment on Bucket. Find yourpublishableKey
underActivity
on https://app.bucket.co.company
,user
andotherContext
make up the context that is used to determine if a feature is enabled or not.company
anduser
contexts are automatically transmitted to Bucket servers so the Bucket app can show you which companies have access to which features etc.If you specify
company
and/oruser
they must have at least theid
property plus anything additional you want to be able to evaluate feature targeting against. See "Managing Bucket context" below.fallbackFeatures
is a list of strings which specify which features to consider enabled if the SDK is unable to fetch features.loadingComponent
lets you specify an React component to be rendered instead of the children while the Bucket provider is initializing. If you want more control over loading screens,useFeature()
returnsisLoading
which you can use to customize the loading experience:
Implement feature targeting
useFeature()
returns the state of a given feature for the current company/user:
This example checks if a user should be shown the Start huddle
button by checking the isEnabled
boolean and then sends an event once the Huddle starts to let Bucket automatically track usage and collect feedback.
Custom event tracking
useTrack()
lets you send custom events to Bucket whenever a user uses a feature:
Add additional hooks
There are additional hooks available:
useRequestFeedback()
: Returns a function that lets you open a dialog to ask for feedback on a specific feature.useSendFeedback()
: Returns a function that lets you send feedback to Bucket.
Complete developer documentation
You can find the complete developer documentation on GitHub.
Last updated