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. It compares the keys by value, in any order, so it evaluates again only when the set of keys changes:

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:

ValuePurpose
data.flagsAll evaluated results, each with key, enabled, variantKey and payload.
isEnabled(key)Whether the flag is enabled. Unknown and still-loading flags return false.
getVariant(key){ enabled, variantKey, payload }, or null while the flag is loading or unknown.
isLoading, error, refetchThe request state (error is null when there is none), and a way to retry the request.

variantKey is null for a flag without variants. A variant may carry a payload, null when it has none. 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, and mounted useFeatureFlags hooks evaluate again for the new person.

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.