Skip to content

useFeatureFlags

useFeatureFlags() exposes the feature flags enabled for the signed-in user. Flags are delivered in the session token’s feature_flags claim, so the hook reads them directly — there’s no network request on render. The set refreshes whenever the session token is re-minted (sign-in and session refresh), and is empty when signed out.

See the Feature flags guide for how flags are created and targeted in the dashboard.

import { useFeatureFlags } from '@torii-js/torii-react';
function Nav() {
const { flags, isEnabled } = useFeatureFlags();
return (
<nav>
{isEnabled('beta-banner') && <BetaBanner />}
{/* `flags` is the full list of enabled keys, e.g. ['beta-banner'] */}
</nav>
);
}

For a single flag, useFeatureFlag(key) is a convenience wrapper:

import { useFeatureFlag } from '@torii-js/torii-react';
function Checkout() {
const newCheckout = useFeatureFlag('new-checkout');
return newCheckout ? <NewCheckout /> : <LegacyCheckout />;
}

useFeatureFlags() returns UseFeatureFlagsResult:

FieldTypeDescription
flagsstring[]Keys of every feature flag enabled for the current user. Empty when signed out or no flags apply.
isEnabled(key: string) => booleanWhether the given flag key is enabled for the current user.

useFeatureFlag(key: string) returns a boolean — shorthand for useFeatureFlags().isEnabled(key).

  • No network call. The enabled set is derived from the session token’s feature_flags claim, so reads are synchronous and free.
  • Refreshes with the session. A flag change reaches the user on their next token refresh (up to the access-token lifetime), not instantly.
  • Empty when signed out. With no active session there are no flags; guard your UI accordingly (e.g. render behind <SignedIn>).
  • Must be called inside a <ToriiProvider>.