In the state lesson, the "Ironing" filter was gone once the system killed the app in the background. For that filter to still be there when Wulan opens the app again, it has to go into local storage: the place an app keeps data on the phone so it's still there after the app closes. There are four such places, much like the ones at Mrs. Rini's front counter: a notebook in the drawer (you open it first, a moment, then read), a small whiteboard on the wall (one glance and it's read), a safe for the shop keys, and a filing cabinet for thousands of receipts. On the phone, those four are AsyncStorage, MMKV, SecureStore and SQLite.
Four places to store data on the phone
The versions npx expo install installs on Expo SDK 57 (checked 11 October 2026):
| Storage | Version | How you read | Expo Go | Good for |
|---|---|---|---|---|
@react-native-async-storage/async-storage |
2.2.0 | async: await getItem(key) |
included | small settings, small caches |
react-native-mmkv + react-native-nitro-modules |
4.3.2 + 0.37.1 | sync: getString(key) |
not included | settings read at startup |
expo-secure-store |
57.0.4 | async, encrypted | included | the login token, small secrets |
expo-sqlite |
57.0.4 | SQL queries | included | lots of data you search and filter |
- AsyncStorage stores key-value pairs, string values, unencrypted. Every call returns a Promise. On Android the total is capped at 6 MB by default. npm already has 3.1.1 (with
createAsyncStorageandgetMany/setMany), but SDK 57 installs 2.2.0, the version Expo tested. - MMKV (made by WeChat) reads and writes synchronously through JSI, a direct JavaScript-to-C++ interface. Version 4 is created with
createMMKV(), no longernew MMKV(), and.delete()became.remove(). Its README claims about 30 times faster than AsyncStorage (reading one value 1,000 times). Its native code isn't in Expo Go, so you need a development build. In Expo Go it stops withNitroModules are not supported in Expo Go!. - SecureStore uses the Keychain on iOS, and SharedPreferences encrypted with the Android Keystore. Its docs warn that large values may be rejected (some iOS versions refused anything above roughly 2,048 bytes). So store the token, not the order data.
- expo-sqlite is a real database. As a bonus,
expo-sqlite/kv-storehas the same API as AsyncStorage, plus sync versions likegetItemSync.
Saving the filter: AsyncStorage and MMKV
// src/state/filter.ts
import AsyncStorage from '@react-native-async-storage/async-storage';
import { create } from 'zustand';
import { createJSONStorage, persist } from 'zustand/middleware';
import type { Status } from '@/data/orders';
type Filter = 'All' | Status;
export const useFilter = create<{ filter: Filter; setFilter: (filter: Filter) => void }>()(
persist(
(set) => ({ filter: 'All', setFilter: (filter) => set({ filter }) }),
{ name: 'orders-filter', storage: createJSONStorage(() => AsyncStorage) },
),
);
Every setFilter('Ironing') writes the key orders-filter holding {"state":{"filter":"Ironing"},"version":0}. Functions aren't stored, because JSON.stringify skips them. The MMKV version only swaps storage:
import { createMMKV } from 'react-native-mmkv';
import type { StateStorage } from 'zustand/middleware';
const mmkv = createMMKV();
const mmkvStorage: StateStorage = {
getItem: (key) => mmkv.getString(key) ?? null,
setItem: (key, value) => mmkv.set(key, value),
removeItem: (key) => { mmkv.remove(key); },
};
// ...then storage: createJSONStorage(() => mmkvStorage)
Guess first: the "Ironing" filter is saved through AsyncStorage, then Wulan closes the app and opens it again. On the first render, which chip is lit? What happens when the app opens again:
| When | AsyncStorage | MMKV |
|---|---|---|
| the store is created | getItem returns a Promise, not done yet |
getString returns the JSON right away |
| first render | filter 'All': the All chip is lit, the list is unfiltered |
filter 'Ironing': the Ironing chip is already lit |
| the Promise resolves | filter becomes 'Ironing', re-render |
no change |
So with AsyncStorage, the first render is still 'All', and a moment later it switches to "Ironing": the list flickers. Zustand can only restore state synchronously when its storage is synchronous. Your options: MMKV, or keep the splash screen until useFilter.persist.hasHydrated() is true.
The order list for a fast start: persisting TanStack Query
The order list is server state, so what you store is the TanStack Query cache, through @tanstack/react-query-persist-client and @tanstack/query-async-storage-persister (5.104.1):
// src/app/_layout.tsx (the query provider part)
import AsyncStorage from '@react-native-async-storage/async-storage';
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister';
import { QueryClient } from '@tanstack/react-query';
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client';
const queryClient = new QueryClient({
defaultOptions: { queries: { gcTime: 1000 * 60 * 60 * 24 } }, // 24 hours, the same as maxAge
});
const persister = createAsyncStoragePersister({ storage: AsyncStorage });
// in RootLayout: wrap <Stack /> in
<PersistQueryClientProvider client={queryClient} persistOptions={{ persister, maxAge: 1000 * 60 * 60 * 24 }}>
- The persister writes the whole cache to the key
REACT_QUERY_OFFLINE_CACHE, at most once per second. - On open, the cache is restored first (
useQuerywaits meanwhile), then the['orders','mine']list shows from the cache without waiting for the server: #13 "Ironing". Then the query fetches again and #13 changes to "Ready for pickup". - If that refetch fails (offline, say), the cached
datais still there butisErrorturnstrue. Show the error screen only when there's no data yet:if (isError && !data). - A cache older than
maxAge(24 hours by default) is thrown away. Setbusterto a new version when the data's shape changes. gcTimemust be equal to or bigger thanmaxAge. It defaults to 5 minutes, so without it the cache is discarded after 5 minutes unused.
What must never be stored in plain text
AsyncStorage and MMKV files are plain text in the app's folder. Other apps can't read them, but a rooted phone and a debug build can.
- The login token:
expo-secure-store(it has been since the API lesson). - Passwords: don't store them at all. Store a token the server can revoke.
- PINs, OTPs, ID numbers, ID photos: not in plain AsyncStorage or MMKV. MMKV can be encrypted (
createMMKV({ id: 'secrets', encryptionKey })), but the key itself must come from SecureStore, not be written in the code. - On logout, clear the cache:
queryClient.clear()thenawait persister.removeClient(). Otherwise the next account on the same phone sees Wulan's orders.
⚠️ Five storage slips that keep happening
- Forgetting
await.AsyncStorage.getItem('orders-filter')withoutawaitgives a Promise, not a string. - Storing an object directly. The value must be a string. AsyncStorage 2.2.0 warns
The value for key "..." is not a string. UseJSON.stringifyandJSON.parse, or letcreateJSONStoragehandle it. - A token in AsyncStorage or MMKV. Its place is SecureStore.
- MMKV in Expo Go. Its native code isn't there. Make a development build.
gcTimesmaller thanmaxAge. The saved cache still gets thrown away by the garbage collector.
TL;DR: AsyncStorage (2.2.0 on SDK 57) stores unencrypted strings through Promises, ships in Expo Go, and is capped at 6 MB on Android. MMKV 4 (createMMKV(), needs react-native-nitro-modules and a development build) reads synchronously through JSI, about 30 times faster according to its README, so a saved filter is already right on the first render, while AsyncStorage shows 'All' first and then flickers to "Ironing". SecureStore (Keychain and Keystore) is only for small secrets like the token. expo-sqlite is for lots of data, with kv-store as an AsyncStorage replacement. For a fast start, persist the TanStack Query cache with PersistQueryClientProvider and createAsyncStoragePersister (maxAge 24 hours, gcTime at least as long). Never store tokens, passwords, PINs or identity data unencrypted, and clear the cache on logout.
⚡ Four places on the phone
Meaning: AsyncStorage stores unencrypted strings through Promises and ships in Expo Go. MMKV reads synchronously through JSI, but needs a development build. SecureStore is for small secrets like the token. expo-sqlite is for lots of data you search and filter.
⚡ A filter that survives
Write:
persist(
(set) => ({ filter: 'All', setFilter: (filter) => set({ filter }) }),
{ name: 'orders-filter', storage: createJSONStorage(() => AsyncStorage) },
)
Guess first: the "Ironing" filter is saved through AsyncStorage, then Wulan closes the app and opens it again. On the first render, which chip is lit?
The All chip. AsyncStorage's getItem returns a Promise, so the filter only becomes "Ironing" a moment later, and the list flickers. With MMKV, the Ironing chip is already lit on the first render.
Meaning: Zustand can only restore state synchronously when its storage is synchronous.
⚡ What must never be plain
Meaning: AsyncStorage and MMKV files are plain text. The login token goes into SecureStore, and passwords aren't stored at all. On logout, clear the cache with queryClient.clear() then await persister.removeClient(), so the next account doesn't see Wulan's orders.