
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
bkt-react-client-sdk
Advanced tools
Bucketeer React Client SDK - A TypeScript React library for feature flagging
This SDK enables seamless access to your feature flags in React applications using Bucketeer. It provides React hooks and components for easy integration, and is built on top of the robust @bucketeer/js-client-sdk.
Bucketeer is an open-source platform created by CyberAgent to help teams make better decisions, reduce deployment lead time and release risk through feature flags. Bucketeer offers advanced features like dark launches and staged rollouts that perform limited releases based on user attributes, devices, and other segments.
[!WARNING] This is a beta version. Breaking changes may be introduced before general release.
For documentation related to flags management in Bucketeer, refer to the Bucketeer documentation website.
npm install @bucketeer/react-client-sdk
React Version Support:
Make sure your
react,react-dom,@types/react, and@types/react-domversions all match.
Initialize the Bucketeer client and provide it to your app using the BucketeerProvider:
Use
defineBKTConfigForReactto create your config anddefineBKTUserto create a user and initializing the client usinginitializeBKTClient
import React, { useEffect, useState } from 'react';
import {
BucketeerProvider,
defineBKTConfigForReact,
defineBKTUser,
initializeBKTClient,
getBKTClient,
destroyBKTClient,
type BKTClient,
} from '@bucketeer/react-client-sdk';
const config = defineBKTConfigForReact({
apiKey: 'your-api-key',
apiEndpoint: 'https://api.example.com',
appVersion: '1.0.0',
featureTag: 'web',
});
const user = defineBKTUser({
id: 'user-123',
customAttributes: {
platform: 'ios',
version: '1.0.0',
},
});
export default function App() {
const [client, setClient] = useState<BKTClient | null>(null);
useEffect(() => {
const init = async () => {
try {
await initializeBKTClient(config, user);
} catch (error) {
if (error instanceof Error && error.name === 'TimeoutException') {
// TimeoutException but The BKTClient SDK has been initialized
console.warn('Bucketeer client initialization timed out, but client is already initialized.');
} else {
console.error('Failed to initialize Bucketeer client:', error);
return;
}
}
try {
const bktClient = getBKTClient()!;
setClient(bktClient);
} catch (error) {
console.error('Failed to initialize Bucketeer client:', error);
}
};
init();
return () => {
destroyBKTClient();
};
}, []);
if (!client) {
return <div>Loading Bucketeer client...</div>;
}
return (
<BucketeerProvider client={client}>
<YourAppContent />
</BucketeerProvider>
);
}
If you see a
TimeoutExceptionerror during initialization, it means the Bucketeer client has already been initialized successfully. This error is safe to ignore and does not affect the client’s functionality.
import React from 'react';
import {
useBooleanVariation,
useStringVariation,
useNumberVariation,
useObjectVariation,
useBooleanVariationDetails,
useStringVariationDetails,
useNumberVariationDetails,
useObjectVariationDetails,
} 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 });
// Feature flag with detailed evaluation information
const featureDetails = useBooleanVariationDetails('advanced-feature', false);
// Access client for advanced operations
const client = useBucketeerClient();
const handleUpdateUser = () => {
client.updateUserAttributes({
plan: 'premium',
region: 'us-west',
});
};
return (
<div>
{showNewFeature && <NewFeature />}
{featureDetails.variationValue && <AdvancedFeature />}
<div>Theme: {theme}</div>
<div>Max items: {maxItems}</div>
<div>Timeout: {config.timeout}ms</div>
<div>Feature reason: {featureDetails.reason}</div>
<button onClick={handleUpdateUser}>Update User</button>
</div>
);
}
BucketeerProviderProvides Bucketeer context to child components. Most users should use the provided hooks for feature flag access; direct context access is for advanced use cases.
Props:
client: BKTClient - Bucketeer client instancechildren: ReactNode - Child components<BucketeerProvider client={client}>
{/* Your app content here */}
<YourAppContent />
</BucketeerProvider>
Inside your components, you can access the Bucketeer client and last updated time using the useContext hook:
import { useContext } from 'react';
import { BucketeerContext } from '@bucketeer/react-client-sdk';
const { client, lastUpdated } = useContext(BucketeerContext);
useBooleanVariation(flagId, defaultValue)Returns a boolean feature flag value.
Parameters:
flagId: string - The feature flag identifierdefaultValue: boolean - Default value if flag is not availableReturns: boolean
useStringVariation(flagId, defaultValue)Returns a string feature flag value.
Parameters:
flagId: string - The feature flag identifierdefaultValue: string - Default value if flag is not availableReturns: string
useNumberVariation(flagId, defaultValue)Returns a number feature flag value.
Parameters:
flagId: string - The feature flag identifierdefaultValue: number - Default value if flag is not availableReturns: number
useObjectVariation<T>(flagId, defaultValue)Returns a JSON/object feature flag value with type safety. Uses the modern objectVariation API.
Parameters:
flagId: string - The feature flag identifierdefaultValue: T - Default value if flag is not availableReturns: T
Note: The generic type T must extend BKTValue (which includes objects, arrays, and primitive values).
useBooleanVariationDetails(flagId, defaultValue)Returns a boolean feature flag value along with detailed evaluation information.
Parameters:
flagId: string - The feature flag identifierdefaultValue: boolean - Default value if flag is not availableReturns: BKTEvaluationDetails<boolean> - Object containing:
variationValue: boolean - The feature flag valuefeatureId: string - The feature flag identifierfeatureVersion: number - Version of the feature flaguserId: string - User ID used for evaluationvariationId: string - ID of the variation returnedvariationName: string - Name of the variationreason: string - Reason for the evaluation resultuseStringVariationDetails(flagId, defaultValue)Returns a string feature flag value along with detailed evaluation information.
Parameters:
flagId: string - The feature flag identifierdefaultValue: string - Default value if flag is not availableReturns: BKTEvaluationDetails<string>
useNumberVariationDetails(flagId, defaultValue)Returns a number feature flag value along with detailed evaluation information.
Parameters:
flagId: string - The feature flag identifierdefaultValue: number - Default value if flag is not availableReturns: BKTEvaluationDetails<number>
useObjectVariationDetails<T>(flagId, defaultValue)Returns a JSON/object feature flag value along with detailed evaluation information.
Parameters:
flagId: string - The feature flag identifierdefaultValue: T - Default value if flag is not availableReturns: BKTEvaluationDetails<T>
Note: The generic type T must extend BKTValue.
useBucketeerClient()Returns the initialized Bucketeer client instance.
Returns: BKTClient | null
import { useBucketeerClient } from '@bucketeer/react-client-sdk';
const client = useBucketeerClient();
Without the hook useBucketeerClient(), you can still access the Bucketeer client using the JS SDK methods:
import { getBKTClient } from '@bucketeer/react-client-sdk';
const client = getBKTClient();
The React SDK re-exports several types from the bkt-js-client-sdk for convenience. Examples include:
BKTConfig - Bucketeer configuration objectBKTUser - User information objectBKTClient - Bucketeer client instanceBKTValue - Valid feature flag value typesBKTEvaluationDetails<T> - Detailed evaluation information for feature flagsdefineBKTConfig - Helper to create configurationdefineBKTUser - Helper to create user objectsFor full JS API reference, see the Bucketeer documentation website.
# Install dependencies
pnpm install
# Run tests
pnpm test
# Run tests with coverage
pnpm test:coverage
# Build the library
pnpm build
# Lint code
pnpm lint
# Format code
pnpm format
# Type check
pnpm type-check
pnpm build - Build the library for productionpnpm dev - Build in watch modepnpm test - Run testspnpm test:watch - Run tests in watch modepnpm test:coverage - Run tests with coverage reportpnpm lint - Lint and fix codepnpm lint:check - Check linting without fixingpnpm format - Format code with Prettierpnpm format:check - Check formatting without fixingpnpm type-check - Run TypeScript type checkingTo see the SDK in action, you can run the included example:
example/env_template file to example/.env and update it with your Bucketeer credentials. Example:VITE_BUCKETEER_API_KEY=your-api-key
VITE_BUCKETEER_API_ENDPOINT=https://your-bucketeer-endpoint
pnpm build
pnpm example:start
This library uses the @bucketeer/js-client-sdk under the hood.
Apache
FAQs
Bucketeer React Client SDK - A TypeScript React library for feature flagging
We found that bkt-react-client-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.