The @hyphen/browser-sdk is Hyphen's native client-side JavaScript SDK for web browsers. It's optimized for evaluating Toggle feature flags in the browser with a minimal bundle size.
Table of Contents
Installation
npm install @hyphen/browser-sdk
Authentication
The SDK authenticates with your project public key (it starts with public_) and your application id. See Get a Project's Public Key for where to find these in the Hyphen dashboard.
Initialization
Provide a defaultContext describing the current user so flags can be targeted correctly:
import { Toggle } from '@hyphen/browser-sdk';
const toggle = new Toggle({
publicApiKey: 'public_your-api-key-here',
applicationId: 'your-app-id',
environment: 'production',
defaultContext: {
targetingKey: 'user-123',
user: {
id: 'user-123',
email: '[email protected]',
name: 'John Doe',
},
},
});
Usage
const isEnabled = await toggle.getBoolean('feature-flag', false);
if (isEnabled) {
console.log('Feature is enabled!');
}
See also
- GitHub: Hyphen/browser-sdk
- Prefer OpenFeature? Use the JavaScript (Web) provider.