Bucketeer React Client SDK - A TypeScript React library for feature flagging
npm install bkt-test-react-client-sdkA React SDK for Bucketeer feature flags, providing React hooks and components for easy integration. Built on top of the bkt-js-client-sdk.
- ๐ React Context and Hooks for easy integration
- ๐ง TypeScript support with full type safety
- โก Real-time feature flag updates
- ๐ฏ Multiple variation types (boolean, string, number, object)
- ๐งช User attribute management
- ๐ฆ Tree-shakeable and lightweight
``bash`
npm install @bucketeer/react-client-sdk
or with yarn:
`bash`
yarn add @bucketeer/react-client-sdk
Wrap your app with the BucketeerProvider:
`tsx
import React from 'react';
import { BucketeerProvider } from '@bucketeer/react-client-sdk';
import { defineBKTConfig, defineBKTUser } from 'bkt-js-client-sdk';
const config = defineBKTConfig({
apiKey: 'your-api-key',
apiEndpoint: 'https://api.bucketeer.io',
appVersion: '1.0.0',
featureTag: 'mobile',
});
const user = defineBKTUser({
id: 'user-123',
customAttributes: {
platform: 'ios',
version: '1.0.0',
},
});
export default function App() {
return (
);
}
`
`tsx
import React from 'react';
import {
useBooleanVariation,
useStringVariation,
useNumberVariation,
useObjectVariation,
useBucketeerClient,
} from '@bucketeer/react-client-sdk';
function MyComponent() {
// Boolean feature flag
const showNewFeature = useBooleanVariation('show-new-feature', false);
// String feature flag
const theme = useStringVariation('app-theme', 'light');
// Number feature flag
const maxItems = useNumberVariation('max-items', 10);
// JSON feature flag
const config = useObjectVariation('app-config', { timeout: 5000 });
// Access client for advanced operations
const { client, updateUserAttributes } = useBucketeerClient();
const handleUpdateUser = () => {
updateUserAttributes({
plan: 'premium',
region: 'us-west',
});
};
return (
API Reference
$3
####
BucketeerProviderProvides Bucketeer context to child components.
Props:
-
config: BKTConfig - Bucketeer configuration
- user: BKTUser - User information
- children: ReactNode - Child components$3
####
useBooleanVariation(flagId, defaultValue)Returns a boolean feature flag value.
Parameters:
-
flagId: string - The feature flag identifier
- defaultValue: boolean - Default value if flag is not availableReturns: boolean
####
useStringVariation(flagId, defaultValue)Returns a string feature flag value.
Parameters:
-
flagId: string - The feature flag identifier
- defaultValue: string - Default value if flag is not availableReturns: string
####
useNumberVariation(flagId, defaultValue)Returns a number feature flag value.
Parameters:
-
flagId: string - The feature flag identifier
- defaultValue: number - Default value if flag is not availableReturns: number
####
useObjectVariationReturns a JSON/object feature flag value with type safety. Uses the modern
objectVariation API.Parameters:
-
flagId: string - The feature flag identifier
- defaultValue: T - Default value if flag is not availableReturns: T
Note: The generic type
T must extend BKTValue (which includes objects, arrays, and primitive values).####
useBucketeerClient()Returns the Bucketeer client instance and utility functions.
Returns:
-
client: BKTClient | null - The Bucketeer client instance
- updateUserAttributes: Function to update user attributesRe-exported Types
The following types are re-exported from
bkt-js-client-sdk for convenience:-
BKTConfig - Bucketeer configuration object
- BKTUser - User information object
- BKTClient - Bucketeer client instance
- BKTValue - Valid feature flag value types
- defineBKTConfig - Helper to create configuration
- defineBKTUser - Helper to create user objectsRunning the Example
To see the SDK in action, you can run the included example:
`bash
Build the SDK
yarn buildStart the example app
yarn example:start
`The example will be available at
http://localhost:3000.Development
$3
This project uses Yarn 4.x with PnP (Plug'n'Play) for better performance and reliability. VS Code requires special configuration to work properly with PnP.
#### Why Yarn PnP?
๐ Key Benefits:
- Faster installs: 5-15s vs 30-60s (no file copying, just resolution maps)
- Disk space efficient: Dependencies shared globally across projects
- Stricter dependencies: Prevents phantom dependency bugs
- Faster CI/CD: Dramatically reduces build times
- Better performance: Direct module resolution vs directory tree walking
- Cleaner repos: No massive
node_modules directories#### IDE Setup (Required for IntelliSense)
If you see these issues in your editor:
- โ "Cannot find module 'bkt-js-client-sdk'" errors
- โ "Cannot find name 'describe', 'it', 'expect'" in test files
- โ Missing auto-imports and IntelliSense
#### VS Code Setup
1. Install the ZipFS extension (maintained by Yarn team):
`
Extension ID: arcanis.vscode-zipfs
`2. Generate VS Code SDK configuration:
`bash
yarn dlx @yarnpkg/sdks vscode
`3. Activate workspace TypeScript (required for safety):
- Press
Ctrl+Shift+P (or Cmd+Shift+P on Mac) in any TypeScript file
- Choose "Select TypeScript Version"
- Pick "Use Workspace Version"4. Restart VS Code completely
#### Other IDEs
For WebStorm, Vim, Neovim, Emacs, and other editors:
`bash
Generate SDKs for your specific editor
yarn dlx @yarnpkg/sdks vim
yarn dlx @yarnpkg/sdks base # For generic editors
`โ
After setup: Full IntelliSense, auto-imports, and dependency resolution should work perfectly.
๐ Complete Setup Guide: Yarn Editor SDKs Documentation
$3
`bash
Install dependencies
yarn installRun tests
yarn testRun tests with coverage
yarn test:coverageBuild the library
yarn buildLint code
yarn lintFormat code
yarn formatType check
yarn type-check
`$3
-
yarn build - Build the library for production
- yarn dev - Build in watch mode
- yarn test - Run tests
- yarn test:watch - Run tests in watch mode
- yarn test:coverage - Run tests with coverage report
- yarn lint - Lint and fix code
- yarn lint:check - Check linting without fixing
- yarn format - Format code with Prettier
- yarn format:check - Check formatting without fixing
- yarn type-check` - Run TypeScript type checkingThis library uses the bkt-js-client-sdk under the hood.
Apache