Skip to content
Gates

GatesProvider

<GatesProvider> makes a client available to useFlag, useGates and useGatesStatus. It takes either the options to create a client, or a client you created yourself with createGates.

Props

PropTypeNotes
projectKeystringThe environment’s ek_… key. Project-wide pk_… keys are still accepted.
environment"development" | "preview" | "production"Must match the key.
apiUrlstringWhere the Gates API lives. Default http://localhost:8790.
userUserIdentity | nullDeclarative identity. null means signed out. The only prop read after mount.
clientGatesClientA client from createGates. When set, the other options are ignored.
storageGatesStorageget / set / remove. Defaults to AsyncStorage.
runtimeRuntimeInfo | () => RuntimeInfoDefaults to discovery from expo-application and expo-updates.
refreshIntervalMsnumberMinimum gap between foreground-triggered refreshes. Default 60 000.
timeoutMsnumberNetwork timeout per request. Default 10 000.
telemetrybooleanSend exposure and adoption events. Default true.
fetchtypeof fetchYour own fetch, for tests or polyfills.
logger{ warn, debug? }Where the SDK reports a degraded storage or a failed sync. Silent by default.
sdkVersionstringReported on sync, for the dashboard’s benefit.

UserIdentity is { id: string; traits?: Record<string, string | number | boolean> }.

Behaviour

  • Children render at once. There is no loading gate.
  • Configuration is read once, like a QueryClient’s. Changing projectKey or environment after mount has no effect; create a new client instead.
  • user is compared by value. When it changes from one user to another the provider calls identify; when it becomes null after a user, it calls reset. The initial user is passed to the client directly, so mount does not trigger an extra sync.
  • When you pass client, the provider does not manage identity for the initial render; it still applies later user transitions.

Example with a shared client

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

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