Skip to content
Gates

Read a flag

import { useFlag } from "@gates/expo";

function Checkout() {
  const v2 = useFlag("checkout-v2"); // false until a snapshot says otherwise
  return v2 ? <CheckoutV2 /> : <CheckoutV1 />;
}

useFlag(key, fallback?) returns a boolean. The component re-renders when a sync or a user change changes the value.

What you get before anything has loaded

On the first frame the client has not read AsyncStorage yet, so useFlag returns the fallback (false by default). The local read takes milliseconds; once it finishes, reads come from the saved snapshot. A snapshot that does not contain the flag also returns the fallback.

Turning it on

Enable the flag in the dashboard. Phones pick up the new revision on their next sync: at startup, when the app returns to the foreground, after identify, or when your app calls refresh(). See Refresh.

Declarative alternatives

<Flag>, <Switch> and <Experiment> are each one useFlag plus a branch, so they record exposure the same way. See Components.

Checking why

gates.explain("checkout-v2");
// { value, reason, ruleId?, bucket?, revision, source, context, audiences }

See explain().