react-native-mmkv

通过 react-native-mmkv(基于 Nitro)为 React Native 提供高速同步键值存储。覆盖 MMKV 实例的创建与配置、对字符串/数字/布尔/缓冲区等类型的读写、用于响应式 UI 的 React 钩子、值变更监听、加密、从 AsyncStorage 的迁移,以及与状态管理库(zustand、redux-persist、jotai、react-query)的集成,还包含存储限制、多进程模式及从基于类的 API 升级到 V4 的相关内容。

仓库最近推送
GitHub Stars
181
Forks
10
Issues / PRs
0

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "react-native-mmkv":https://skillpi.com/zh/skills/deepskill-ee0b73a25008dbfbb61818c42b9c6fc1cfc65ccd28291e119655fdd57aa37b8b。安装前核对上游来源和版本:https://github.com/margelo/react-native-skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

通过 react-native-mmkv(基于 Nitro)为 React Native 提供高速同步键值存储。覆盖 MMKV 实例的创建与配置、对字符串/数字/布尔/缓冲区等类型的读写、用于响应式 UI 的 React 钩子、值变更监听、加密、从 AsyncStorage 的迁移,以及与状态管理库(zustand、redux-persist、jotai、react-query)的集成,还包含存储限制、多进程模式及从基于类的 API 升级到 V4 的相关内容。

0 下载

介绍来源: third_party · margelo · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: react-native-mmkv
description: Fast 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, AsyncStorage migration, and state-management integrations (zustand, redux-persist, jotai, react-query). Also covers storage limits, multi-process mode, and the V4 upgrade from the class-based API.
license: MIT
metadata:
  author: margelo
  scope: react-native-mmkv
  tags: react-native, mmkv, storage, key-value, encryption, hooks, zustand, redux, jotai, react-query, async-storage, migration, nitro-modules

react-native-mmkv

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.

Mental model

react-native-mmkv is a high-performance, synchronous key-value storage library for React Native, backed by Tencent's MMKV C++ engine via Nitro Modules (JSI). It is ~30x faster than AsyncStorage.

The three things that trip people up:

  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.
  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 or WatermelonDB. There is no fixed storage limit — but memory warnings will fire if you go too large.
  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.

V4 requires React Native 0.75+. It works on both the New Architecture and the old architecture (Nitro is backwards compatible).

Routing table — problem to reference

Load the matching file from references/ before writing code. Each reference cites real APIs from the library.

User is asking about… Read
Creating an MMKV instance, configuration options (id, path, encryptionKey, mode, readOnly, compareBeforeSet), the createMMKV() factory references/create-instance.md
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
React hooks (useMMKVString, useMMKVNumber, useMMKVBoolean, useMMKVBuffer, useMMKVObject, useMMKV, useMMKVListener, useMMKVKeys), reactive UI references/hooks.md
Listening for value changes outside of React, addOnValueChangedListener, cleaning up listeners references/listeners.md
Encryption (encrypt, decrypt, recrypt), AES-128 vs AES-256, encryptionKey config references/encryption.md
Migrating from AsyncStorage, data transfer pattern, completion flag references/migrate-from-async-storage.md
zustand persist middleware, redux-persist, jotai atomWithMMKV, react-query persister, MobX references/state-management.md
V4 upgrade, breaking changes from V3, new MMKV() → createMMKV(), .delete() → .remove() references/upgrade-v4.md
Storage size limits, memory warnings, when to use a database instead references/limits-and-gotchas.md

If the question doesn't match any row, read references/create-instance.md first — most setup questions start there.

Installation

npm install react-native-mmkv react-native-nitro-modules
cd ios && pod install

Expo:

npx expo install react-native-mmkv react-native-nitro-modules
npx expo prebuild

After install, rebuild the app. No additional native wiring is required.

Quick reference — full MMKV instance API

import { createMMKV, existsMMKV, deleteMMKV } from 'react-native-mmkv'

const storage = createMMKV({ id: 'my-store' })

// Properties (read-only)
storage.id          // string
storage.length      // number of keys
storage.byteSize    // total file size in bytes
storage.size        // (deprecated — use byteSize)
storage.isReadOnly  // boolean
storage.isEncrypted // boolean

// Write
storage.set('key', 'string' | 42 | true | arrayBuffer)

// Read
storage.getString('key')   // string | undefined
storage.getNumber('key')   // number | undefined
storage.getBoolean('key')  // boolean | undefined
storage.getBuffer('key')   // ArrayBuffer | undefined

// Keys
storage.contains('key')    // boolean
storage.getAllKeys()        // string[]
storage.remove('key')      // boolean  (NOTE: was .delete() in V3)
storage.clearAll()         // void

// Encryption
storage.encrypt('password')
storage.encrypt('password', 'AES-256')
storage.decrypt()
storage.recrypt('newPassword' | undefined)  // (deprecated — use encrypt()/decrypt())

// Maintenance
storage.trim()                       // free unused space
storage.importAllFrom(otherStorage)  // returns count imported

// Listeners
const sub = storage.addOnValueChangedListener((key) => { ... })
sub.remove()

// Static helpers
existsMMKV('my-store')   // boolean
deleteMMKV('my-store')   // boolean

Testing

A mocked MMKV instance is automatically used when testing with Jest or Vitest. Use createMMKV() as normal in tests — no manual mocking needed.

Verifying the skill is loaded

Good test questions:

  • "How do I persist zustand state with MMKV?" → should produce a StateStorage adapter using storage.set, storage.getString, storage.remove — not AsyncStorage wrappers.
  • "How do I migrate from AsyncStorage to MMKV?" → should show the batch-copy pattern with a completion flag, not a drop-in replacement.
  • "What's the storage limit?" → should explain there's no fixed limit, but data is memory-mapped so keep it under ~100 MB; use SQLite for larger datasets.

References

File Description
create-instance.md createMMKV() factory, all configuration options
crud-operations.md Set/get all types, key management, objects, buffers
hooks.md All React hooks for reactive MMKV usage
listeners.md addOnValueChangedListener, cleanup
encryption.md Encrypt/decrypt instances, AES options
migrate-from-async-storage.md Full migration pattern from AsyncStorage
state-management.md zustand, redux-persist, jotai, react-query, MobX
upgrade-v4.md V3 → V4 breaking changes and migration
limits-and-gotchas.md Storage limits, multi-process, logging, common pitfalls

Problem → Reference Mapping

Problem Reference Action
Don't know where to start create-instance.md Create instance with createMMKV()
Need reactive UI updates hooks.md Use useMMKVString / useMMKVObject etc.
Encrypting sensitive data encryption.md Call storage.encrypt(key)
App uses AsyncStorage, want to switch migrate-from-async-storage.md Batch migrate then swap calls
Zustand/Redux/Jotai persistence state-management.md Wire adapter for your state lib
Upgrading from V3 to V4 upgrade-v4.md new MMKV() → createMMKV(), .delete() → .remove()
Storage growing too large limits-and-gotchas.md Trim or move to SQLite
Multi-process data sharing limits-and-gotchas.md Set mode: 'multi-process'

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值95/100

亮点

  • 解决 React Native 中高性能同步键值存储的明确痛点,比 AsyncStorage 快约30倍
  • 覆盖完整的使用场景:实例创建、CRUD操作、React钩子、监听器、加密、状态管理集成、迁移指南等
  • 提供清晰的 mental model 和常见陷阱说明,帮助用户正确理解和使用
触发精准90/100

待提升项

  • description写错位置 原报告严重程度:轻微

    description 内容位于 skill_body 内部而非顶层 frontmatter

    改进建议:将 description 移至顶层 frontmatter 中以符合规范

亮点

  • 触发词覆盖全面,包括 react-native-mmkv、Nitro、键值存储、加密、zustand、redux-persist 等关键词
  • 提供了清晰的 routing table 帮助用户快速定位到相关参考文档
结构规范90/100

亮点

  • 结构清晰,包含 mental model、routing table、installation、quick reference、testing 等完整章节
  • 提供了详细的 API 参考和代码示例
  • 包含验证问题和参考文档映射,便于用户理解和使用
执行可靠90/100

亮点

  • 提供了完整的安装说明,包括 npm 和 Expo 两种方式
  • API 描述准确,包含所有主要方法和属性
  • 包含测试说明和验证问题,确保 Skill 能正确响应用户查询
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 48, 54, 55 行
文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • github.com

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。