React SDK

Install SDK

npm i @bucketco/react-sdk

Initialize Bucket to fetch feature flags and start listening for Live Satisfaction events.

import BucketProvider from "@bucketco/react-sdk"

<BucketProvider
    publishableKey="{YOUR_PUBLISHABLE_KEY}"
    context={{
        // The context should take the form of { user: { id }, company: { id } }
        // plus anything additional you want to be able to evaluate flags against.
        user: { id: "john_doe" },
        company: { id: "acme_inc" },
    }}
>
    <YourApp />
</BucketProvider>

Create a Release on Bucket

See Create your first Release

Flag evaluation and feature tracking

useFeatureFlag()

Returns the state of a given feature flag for the current context, e.g.

import { useFeatureFlag } from "@bucketco/react-sdk";

const joinHuddleFlag = useFeatureFlag("join-huddle");
//{
//    "isLoading": false,
//    "value": true,
//}

useBucket()

Returns the instance of the Bucket Tracking SDK in use. This can be used to make calls to Bucket, including trackand feedback calls, e.g.

import { useBucket } from "@bucketco/react-sdk";

const bucket = useBucket();

bucket.track("sent_message", { foo: "bar" }, "john_doe", "company_id");

Full documentation

See the full documentation on GitHub.

Last updated