Documentation comes from this release commit, without inheriting newer content. Commit: cc3dd17e61.
State management
Two kinds of state:
See data-fetching.md for server state.
Layer overview
MMKV adapter
A single MMKV instance backs all persisted stores. The adapter implements zustand's StateStorage so it plugs into the persist middleware via createJSONStorage.
Why one instance: smaller binary footprint, shared OS-level handle, and a single place to swap to encrypted MMKV later (createMMKV({ id: 'app', encryptionKey: '...' })).
Persisted vs ephemeral stores
Rule of thumb: persist only what you'd want a returning user to see (their onboarding completion, their session). Never persist server-derived data — that's React Query's job and it has TTL/staleness rules.
If a persisted store sets version, it must also set migrate (identity is fine when the shape did not change). Without migrate, zustand logs State loaded from storage couldn't be migrated since no migrate function was provided and discards any snapshot written at a lower version — including older installs that stored version: 0 before version was added.
Exception: useRemoteConfigStore caches the last successful Firebase Remote Config snapshot under MMKV key remote-config. Product flags (enableIAP, is_public, fs_logic, …) must not snap back to source-code defaults when a launch is offline or the 8s fetch times out. A successful fetch rebuilds from in-app defaults + Firebase-resolved params (remote console values and RC defaultConfig); SDK static keys stay on the in-app schema defaults. The fetch-attempt flag hydrated is in-memory only.
Store anatomy — persisted
Store anatomy — ephemeral
Hydration & boot
zustand/persist is synchronous when paired with MMKV, so the <Stack.Protected> guards in app/_layout.tsx can read hasCompleted and session on first render and pick the right group immediately. Splash gating is handled separately by expo-font + SplashScreen.hideAsync() in the same root layout — see routing.md.
Partializing what you persist
For sensitive or derived state, use partialize to whitelist the keys that hit disk. useAuthStore only persists session:
Clearing state
The Profile screen exposes a debug "Reset onboarding flow" action so QA can repeat the full onboarding → paywall → tutorial sequence without reinstalling.
When NOT to use a zustand store
- The state is server-owned → use a
useQuery. - The state belongs to one component → use
useState. - The state is derived → compute in
useMemofrom inputs. - The state is form-local → keep in the component or a form library.