principletypescriptreact-nativeTip
AsyncStorage vs MMKV: Choosing Storage for React Native
Viewed 0 times
MMKVAsyncStoragesynchronous storageperformancekey-valueencryptionpreferences
Problem
AsyncStorage (the community package) is asynchronous, slow for frequent reads/writes, and can block rendering when used naively. Developers need to understand when to use synchronous storage.
Solution
Use
@react-native-async-storage/async-storage only for infrequent, large data blobs or when you need a simple key-value store with a promise API. Use react-native-mmkv for all performance-sensitive storage: auth tokens, feature flags, user preferences, small state snapshots.Why
MMKV is a C++ key-value store from WeChat. It uses mmap for I/O and operates synchronously. Reads are 30-50x faster than AsyncStorage in benchmarks. It also supports encryption at rest.
Gotchas
- MMKV requires native code — it does not work in Expo Go (requires a development build)
- MMKV stores are not automatically shared between processes on Android (main app vs background tasks)
- AsyncStorage on Android has a 6MB default limit; larger data needs SQLite or file system
- Do not call AsyncStorage in the render function; always use useEffect or event handlers
Code Snippets
MMKV basic usage and Zustand persistence adapter
import { MMKV } from 'react-native-mmkv';
export const storage = new MMKV();
// Synchronous — safe to call anywhere
storage.set('user.token', 'abc123');
const token = storage.getString('user.token');
storage.delete('user.token');
// With Zustand persist middleware
import { StateStorage } from 'zustand/middleware';
export const mmkvStorage: StateStorage = {
getItem: (name) => storage.getString(name) ?? null,
setItem: (name, value) => storage.set(name, value),
removeItem: (name) => storage.delete(name),
};Revisions (0)
No revisions yet.