$npx -y skills add margelo/react-native-skills --skill react-native-mmkvFast synchronous key-value storage for React Native via react-native-mmkv (Nitro-backed). Covers creating and configuring MMKV instances, reading/writing all value types (string, number, boolean, buffer), React hooks for reactive UI, value-change listeners, encryption, AsyncStora
| 1 | # react-native-mmkv |
| 2 | |
| 3 | A focused reference for AI coding assistants working in a project that uses `react-native-mmkv`. Answer using the real APIs from this library — not invented ones — by routing to the matching `references/*.md` file below. |
| 4 | |
| 5 | ## Mental model |
| 6 | |
| 7 | `react-native-mmkv` is a high-performance, synchronous key-value storage library for React Native, backed by Tencent's [MMKV](https://github.com/Tencent/MMKV) C++ engine via Nitro Modules (JSI). It is ~30x faster than AsyncStorage. |
| 8 | |
| 9 | The three things that trip people up: |
| 10 | |
| 11 | 1. **Everything is synchronous.** No `await`, no Promises. `storage.getString('key')` returns the value immediately. This is the whole point — MMKV memory-maps files and reads/writes in-process. |
| 12 | 2. **It's a key-value store, not a database.** All data is cached in memory. Keep total size under ~100 MB; for larger datasets use [react-native-nitro-sqlite](https://github.com/margelo/react-native-nitro-sqlite) or WatermelonDB. There is no fixed storage limit — but memory warnings will fire if you go too large. |
| 13 | 3. **V4 is a breaking rewrite.** The constructor changed from `new MMKV()` to `createMMKV()`, `.delete()` became `.remove()`, and `react-native-nitro-modules` is now a required peer dependency. See the [upgrade guide](./references/upgrade-v4.md). |
| 14 | |
| 15 | > **V4 requires React Native 0.75+.** It works on both the New Architecture and the old architecture (Nitro is backwards compatible). |
| 16 | |
| 17 | ## Routing table — problem to reference |
| 18 | |
| 19 | Load the matching file from `references/` before writing code. Each reference cites real APIs from the library. |
| 20 | |
| 21 | | User is asking about… | Read | |
| 22 | |---|---| |
| 23 | | Creating an MMKV instance, configuration options (`id`, `path`, `encryptionKey`, `mode`, `readOnly`, `compareBeforeSet`), the `createMMKV()` factory | [`references/create-instance.md`](./references/create-instance.md) | |
| 24 | | Getting/setting values, all data types (string, number, boolean, buffer, objects via JSON), key management (`contains`, `getAllKeys`, `remove`, `clearAll`), `size`, `trim`, `importAllFrom` | [`references/crud-operations.md`](./references/crud-operations.md) | |
| 25 | | React hooks (`useMMKVString`, `useMMKVNumber`, `useMMKVBoolean`, `useMMKVBuffer`, `useMMKVObject`, `useMMKV`, `useMMKVListener`, `useMMKVKeys`), reactive UI | [`references/hooks.md`](./references/hooks.md) | |
| 26 | | Listening for value changes outside of React, `addOnValueChangedListener`, cleaning up listeners | [`references/listeners.md`](./references/listeners.md) | |
| 27 | | Encryption (`encrypt`, `decrypt`, `recrypt`), AES-128 vs AES-256, `encryptionKey` config | [`references/encryption.md`](./references/encryption.md) | |
| 28 | | Migrating from AsyncStorage, data transfer pattern, completion flag | [`references/migrate-from-async-storage.md`](./references/migrate-from-async-storage.md) | |
| 29 | | zustand persist middleware, redux-persist, jotai `atomWithMMKV`, react-query persister, MobX | [`references/state-management.md`](./references/state-management.md) | |
| 30 | | V4 upgrade, breaking changes from V3, `new MMKV()` → `createMMKV()`, `.delete()` → `.remove()` | [`references/upgrade-v4.md`](./references/upgrade-v4.md) | |
| 31 | | Storage size limits, memory warnings, when to use a database instead | [`references/limits-and-gotchas.md`](./references/limits-and-gotchas.md) | |
| 32 | |
| 33 | If the question doesn't match any row, read [`references/create-instance.md`](./references/create-instance.md) first — most setup questions start there. |
| 34 | |
| 35 | ## Installation |
| 36 | |
| 37 | ```bash |
| 38 | npm install react-native-mmkv react-native-nitro-modules |
| 39 | cd ios && pod install |
| 40 | ``` |
| 41 | |
| 42 | Expo: |
| 43 | ```bash |
| 44 | npx expo install react-native-mmkv react-native-nitro-modules |
| 45 | npx expo prebuild |
| 46 | ``` |
| 47 | |
| 48 | After install, rebuild the app. No additional native wiring is required. |
| 49 | |
| 50 | ## Quick reference — full MMKV instance API |
| 51 | |
| 52 | ```ts |
| 53 | import { createMMKV, existsMMKV, deleteMMKV } from 'react-native-mmkv' |
| 54 | |
| 55 | const storage = createMMKV({ id: 'my-store' }) |
| 56 | |
| 57 | // Properties (read-only) |
| 58 | storage.id // string |
| 59 | storage.length // number of keys |
| 60 | storage.byteSize // total file size in bytes |
| 61 | storage.size // (deprecated — use byteSize) |
| 62 | storage.isReadOnly // boolean |
| 63 | storage.isEncrypted // boolean |
| 64 | |
| 65 | // Write |
| 66 | storage.set('key', 'string' | 42 | true | arrayBuffer) |
| 67 | |
| 68 | // Read |
| 69 | storage.getString('key') // string | undefined |
| 70 | storage.getNumber('key') |