Evaluate feature flags
Gate features with remotely evaluated flags and variants.
Feature flags let you turn features on or off, and pick variants, without shipping a new build. Voidhash evaluates every flag for the current person, so the same flag can resolve differently for different customers. Use flags for staged rollouts, experiments, and remote configuration.
Evaluate flags
The useFeatureFlags hook evaluates the keys you pass it. Define the key array once, outside the
component, so the hook does not re-run on every render:
const FLAG_KEYS = ["new-onboarding", "pricing-test"];
export function HomeScreen() {
const { getVariant, isEnabled, isLoading } = voidhash.useFeatureFlags(FLAG_KEYS);
if (isLoading) return null;
const pricing = getVariant("pricing-test");
return (
<Home
newOnboarding={isEnabled("new-onboarding")}
pricingVariant={pricing?.enabled ? pricing.variantKey : null}
/>
);
}The hook returns these values:
| Value | Purpose |
|---|---|
data.flags | All evaluated results. |
isEnabled(key) | Whether the flag is enabled. Unknown and still-loading flags return false. |
getVariant(key) | The enabled state, variant key, and optional payload, or null. |
isLoading, error, refetch | The request state, and a way to retry the request. |
A variant may carry a payload. Payloads are untyped JSON, so validate a payload before you use it.
Identity behavior
Flag results are scoped to the current person. The SDK clears them after identify() or a
sign-out or reset, so one customer never sees another customer's assignment.
Choose a safe default to use while a flag is loading or unavailable. Do not use a feature flag to gate paid access. Use entitlement grants for that instead.