Skip to content
Gates

createGates (outside React)

// gates.ts
import { createGates } from "@gates/expo";
export const gates = createGates({
  projectKey: "ek_…",
  environment: "production",
  apiUrl: "https://gates.example.com",
});

// App.tsx
<GatesProvider client={gates}>…</GatesProvider>;

// anywhere
if (gates.flag("checkout-v2")) navigation.navigate("CheckoutV2");

The Expo createGates sets up AsyncStorage, the runtime from expo-application and expo-updates, and an AppState listener that calls onForeground() when the app becomes active. destroy() removes the listener, flushes telemetry and stops timers.

The client

MemberWhat it does
readyA promise that resolves once the local snapshot has been read (or found absent). Never waits on the network.
flag(key, fallback?)Synchronous, local, never throws, never fetches. fallback answers when the flag is unknown.
explain(key)The same decision with its reasons. See explain().
identify(user)Attach a user. See identify and reset.
reset()Forget the user.
refresh()Force a sync. Resolves true when the snapshot changed. See Refresh.
adopt(key)Record that the person used the feature behind key.
status()The current GatesStatus.
subscribe(listener)Called on any change (snapshot, user, status). Returns the unsubscribe function.
onForeground()Refreshes if refreshIntervalMs has elapsed since the last sync attempt; otherwise flushes telemetry.
destroy()Flush telemetry and stop timers.

Splash screen (optional)

The SDK never blocks rendering. If you would rather not render the fallback for the first frame, wait for ready. It resolves after the local read and never waits on the network:

SplashScreen.preventAutoHideAsync();
gates.ready.then(() => SplashScreen.hideAsync());

@gates/expo/core

The same client with no React, React Native or Expo imports, for Node, web, Jest and vitest. runtime is required there (an object or a function returning one, sync or async), storage defaults to memory, and fetch can be swapped for a fake. It also exports createMemoryStorage, DEFAULT_API_URL, DEFAULT_REFRESH_INTERVAL_MS, IDENTIFY_SYNC_DELAY_MS, SDK_VERSION, stateKey and INSTALLATION_ID_KEY.

import { createGates, createMemoryStorage } from "@gates/expo/core";

const gates = createGates({
  projectKey: "ek_test",
  environment: "development",
  runtime: {
    platform: "ios",
    appVersion: "2.4.0",
    buildVersion: "83",
    runtimeVersion: "2.4.0",
    updateId: null,
  },
  storage: createMemoryStorage(),
  fetch: fakeFetch,
});