@amazon-devices/react-native-mmkv

中文文档
1.0.12发布于 2026/10/30See license in LICENSETypeScriptESM + CJS近 30 天下载 5585

The fastest key/value storage for React Native. ~30x faster than AsyncStorage! Works on Android, iOS and Web.

原始使用文档
文档目录28 节
  1. The fastest key/value storage for React Native.
  2. Features
  3. react-native-mmkv V3
  4. Benchmark
  5. Installation
  6. React Native
  7. Expo
  8. Usage
  9. Create a new instance
  10. Set
  11. Get
  12. Hooks
  13. Keys
  14. Objects
  15. Encryption
  16. Buffers
  17. Size
  18. Testing with Jest or Vitest
  19. Documentation
  20. LocalStorage and In-Memory Storage (Web)
  21. Limitations
  22. Integrations
  23. Flipper
  24. Reactotron
  25. Community Discord
  26. Adopting at scale
  27. Contributing
  28. License
react-native-mmkv

MMKV

The fastest key/value storage for React Native.


  • MMKV is an efficient, small mobile key-value storage framework developed by WeChat. See Tencent/MMKV for more information
  • react-native-mmkv is a library that allows you to easily use MMKV inside your React Native app through fast and direct JS bindings to the native C++ library.

Features

  • Get and set strings, booleans, numbers and ArrayBuffers
  • Fully synchronous calls, no async/await, no Promises, no Bridge.
  • Encryption support (secure storage)
  • Multiple instances support (separate user-data with global data)
  • Customizable storage location
  • High performance because everything is written in C++
  • ~30x faster than AsyncStorage
  • Uses JSI and C++ TurboModules instead of the "old" Bridge
  • iOS, Android and Web support
  • Easy to use React Hooks API

react-native-mmkv V3

[!IMPORTANT] react-native-mmkv V3 is now a pure C++ TurboModule, and requires the new architecture to be enabled. (react-native 0.75+)

  • If you want to use react-native-mmkv 3.x.x, you need to enable the new architecture in your app (see "Enable the New Architecture for Apps")
  • If you cannot use the new architecture yet, downgrade to react-native-mmkv 2.x.x for now.

Benchmark

StorageBenchmark compares popular storage libraries against each other by reading a value from storage for 1000 times:

MMKV vs other storage libraries: Reading a value from Storage 1000 times.
Measured in milliseconds on an iPhone 11 Pro, lower is better.

Installation

React Native

yarn add react-native-mmkv
cd ios && pod install

Expo

npx expo install react-native-mmkv
npx expo prebuild

Usage

Create a new instance

To create a new instance of the MMKV storage, use the MMKV constructor. It is recommended that you re-use this instance throughout your entire app instead of creating a new instance each time, so export the storage object.

Default

import { MMKV } from 'react-native-mmkv'

export const storage = new MMKV()

This creates a new storage instance using the default MMKV storage ID (mmkv.default).

App Groups or Extensions

If you want to share MMKV data between your app and other apps or app extensions in the same group, open Info.plist and create an AppGroup key with your app group's value. MMKV will then automatically store data inside the app group which can be read and written to from other apps or app extensions in the same group by making use of MMKV's multi processing mode. See Configuring App Groups.

Customize

import { MMKV, Mode } from 'react-native-mmkv'

export const storage = new MMKV({
  id: `user-${userId}-storage`,
  path: `${USER_DIRECTORY}/storage`,
  encryptionKey: 'hunter2',
  mode: Mode.MULTI_PROCESS
})

This creates a new storage instance using a custom MMKV storage ID. By using a custom storage ID, your storage is separated from the default MMKV storage of your app.

The following values can be configured:

  • id: The MMKV instance's ID. If you want to use multiple instances, use different IDs. For example, you can separate the global app's storage and a logged-in user's storage. (required if path or encryptionKey fields are specified, otherwise defaults to: 'mmkv.default')
  • path: The MMKV instance's root path. By default, MMKV stores file inside $(Documents)/mmkv/. You can customize MMKV's root directory on MMKV initialization (documentation: iOS / Android)
  • encryptionKey: The MMKV instance's encryption/decryption key. By default, MMKV stores all key-values in plain text on file, relying on iOS's/Android's sandbox to make sure the file is encrypted. Should you worry about information leaking, you can choose to encrypt MMKV. (documentation: iOS / Android)
  • mode: The MMKV's process behaviour - when set to MULTI_PROCESS, the MMKV instance will assume data can be changed from the outside (e.g. App Clips, Extensions or App Groups).

Set

storage.set('user.name', 'Marc')
storage.set('user.age', 21)
storage.set('is-mmkv-fast-asf', true)

Get

const username = storage.getString('user.name') // 'Marc'
const age = storage.getNumber('user.age') // 21
const isMmkvFastAsf = storage.getBoolean('is-mmkv-fast-asf') // true

Hooks

const [username, setUsername] = useMMKVString('user.name')
const [age, setAge] = useMMKVNumber('user.age')
const [isMmkvFastAsf, setIsMmkvFastAf] = useMMKVBoolean('is-mmkv-fast-asf')

Keys

// checking if a specific key exists
const hasUsername = storage.contains('user.name')

// getting all keys
const keys = storage.getAllKeys() // ['user.name', 'user.age', 'is-mmkv-fast-asf']

// delete a specific key + value
storage.delete('user.name')

// delete all keys
storage.clearAll()

Objects

const user = {
  username: 'Marc',
  age: 21
}

// Serialize the object into a JSON string
storage.set('user', JSON.stringify(user))

// Deserialize the JSON string into an object
const jsonUser = storage.getString('user') // { 'username': 'Marc', 'age': 21 }
const userObject = JSON.parse(jsonUser)

Encryption

// encrypt all data with a private key
storage.recrypt('hunter2')

// remove encryption
storage.recrypt(undefined)

Buffers

const buffer = new ArrayBuffer(3)
const dataWriter = new Uint8Array(buffer)
dataWriter[0] = 1
dataWriter[1] = 100
dataWriter[2] = 255
storage.set('someToken', buffer)

const buffer = storage.getBuffer('someToken')
console.log(buffer) // [1, 100, 255]

Size

// get size of MMKV storage in bytes
const size = storage.size
if (size >= 4096) {
  // clean unused keys and clear memory cache
  storage.trim()
}

Testing with Jest or Vitest

A mocked MMKV instance is automatically used when testing with Jest or Vitest, so you will be able to use new MMKV() as per normal in your tests. Refer to package/example/test/MMKV.test.ts for an example using Jest.

Documentation

LocalStorage and In-Memory Storage (Web)

If a user chooses to disable LocalStorage in their browser, the library will automatically provide a limited in-memory storage as an alternative. However, this in-memory storage won't persist data, and users may experience data loss if they refresh the page or close their browser. To optimize user experience, consider implementing a suitable solution within your app to address this scenario.

Limitations

  • react-native-mmkv V3 requires react-native 0.74 or higher.
  • react-native-mmkv V3 requires the new architecture/TurboModules to be enabled.
  • Since react-native-mmkv uses JSI for synchronous native method invocations, remote debugging (e.g. with Chrome) is no longer possible. Instead, you should use Flipper or React DevTools.

Integrations

Flipper

Use flipper-plugin-react-native-mmkv to debug your MMKV storage using Flipper. You can also simply console.log an MMKV instance.

Reactotron

Use reactotron-react-native-mmkv to automatically log writes to your MMKV storage using Reactotron. See the docs for how to setup this plugin with Reactotron.

Community Discord

Join the Margelo Community Discord to chat about react-native-mmkv or other Margelo libraries.

Adopting at scale

react-native-mmkv is provided as is, I work on it in my free time.

If you're integrating react-native-mmkv in a production app, consider funding this project and contact me to receive premium enterprise support, help with issues, prioritize bugfixes, request features, help at integrating react-native-mmkv, and more.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

版本与发布记录

@amazon-devices/react-native-mmkv 共发布 6 个版本,首次发布于 2025/09/25;过去 12 个月发布了 4 个版本。

版本发布日期距今
1.0.12latest2026/10/309 天前
1.0.112026/08/073 个月前
1.0.11-rn-83rn83-alpha2026/06/244 个月前
1.0.102026/06/184 个月前
1.0.52025/09/301.1 年前
1.0.22025/09/251.1 年前

关于 @amazon-devices/react-native-mmkv 的常见问题

@amazon-devices/react-native-mmkv 是什么?

The fastest key/value storage for React Native. ~30x faster than AsyncStorage! Works on Android, iOS and Web.

如何安装 @amazon-devices/react-native-mmkv?

在项目目录运行 npm install @amazon-devices/react-native-mmkv,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@amazon-devices/react-native-mmkv 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@amazon-devices/react-native-mmkv 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@amazon-devices/react-native-mmkv 可以商用吗?

@amazon-devices/react-native-mmkv 使用 See license in LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@amazon-devices/react-native-mmkv 的下载量有多少?

根据 npm 官方下载统计,@amazon-devices/react-native-mmkv 在 2026/10/06 – 2026/11/04 这 30 天内被下载 5,585 次,日均约 186 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amazon-devices/react-native-mmkv 还在维护吗?

最新版本 1.0.12 发布于 2026/10/30(9 天前);至今共发布 6 个版本,其中过去 12 个月发布了 4 个;首次发布于 2025/09/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。