Skip to content
Gates

useFlag, useGates, useGatesStatus

useFlag(key, fallback = false)

Returns a boolean: the flag’s value now, evaluated locally. The component re-renders when a sync or an identity change changes the value. Before the local snapshot has been read, and for a flag the snapshot does not contain, it returns fallback.

Reading a flag records one exposure event per flag, revision and user (see Telemetry).

const oneTap = useFlag("checkout-v2");
const legacy = useFlag("legacy-checkout", true);

useGates()

Returns the GatesClient from the nearest provider, for flag, explain, identify, reset, refresh, adopt, status and subscribe. Throws if there is no <GatesProvider> above.

const gates = useGates();
<Button title="Buy now" onPress={() => gates.adopt("checkout-v2")} />;

useGatesStatus()

Returns the client’s GatesStatus and re-renders when it changes:

FieldTypeMeaning
readybooleanThe local snapshot read has been attempted (hit or miss). Evaluation is meaningful from here.
refreshingbooleanA refresh() your app asked for is in flight. Background syncs never set it.
source"none" | "cache" | "remote"Where the current flags came from.
revisionnumberThe snapshot revision the device holds; 0 before any snapshot.
syncedAtnumber | nullUnix ms of the last successful sync, or of the cached snapshot.
lastErrorstring | nullThe last sync failure, kept until the next success. Never affects evaluation.
installationIdstring | nullThis install’s id, once storage has been read.
const { refreshing } = useGatesStatus();
<ScrollView
  refreshControl={<RefreshControl refreshing={refreshing} onRefresh={gates.refresh} />}
/>;

All three hooks live in a module with no react-native import, so they render under vitest with react-test-renderer.