Local Storage (AsyncStorage, MMKV) — Mobile

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…

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

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 }}>

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.

⚠️ Five storage slips that keep happening

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.

What you will learn