gitmyhub

react-native-mmkv

TypeScript ★ 8.4k updated 17d ago

⚡️ The fastest key/value storage for React Native. ~30x faster than AsyncStorage!

A React Native storage library that is about 30x faster than AsyncStorage by calling native C++ code directly through JSI, with support for encryption, multiple instances, and React hooks for automatic re-renders.

TypeScriptC++React NativeJavaScriptsetup: moderatecomplexity 3/5

React Native MMKV is a storage library for React Native apps that lets you save and retrieve small pieces of data, like user preferences or session tokens, very quickly. It wraps MMKV, a key-value storage framework originally built by WeChat for their mobile apps, and makes it available to JavaScript code running in React Native. The library claims to be around 30 times faster than AsyncStorage, which is the storage solution built into React Native by default.

The speed comes from how the library connects JavaScript to the native device code. Instead of going through the older React Native bridge, which passes messages back and forth asynchronously, this library uses a lower-level mechanism called JSI that allows JavaScript to call C++ functions directly and synchronously. That means when you read or write a value, the result is available immediately without waiting for a Promise or callback.

You can store strings, numbers, booleans, and raw binary buffers. The library also supports optional encryption, so stored data can be protected with a key using AES-128 or AES-256. You can create multiple separate storage instances, which is useful for keeping different users' data isolated from one another, or for separating app-wide settings from per-user data. Storage can also be shared with iOS app extensions or widget targets through Apple's App Groups feature.

For React developers, the library provides hooks that make storage values behave like regular state, so when a stored value changes, any component using it re-renders automatically. It works on iOS, Android, and Web.

Installation follows standard React Native package steps, and there is a separate Expo integration. Version 4, the current release, uses a newer binding system called Nitro Modules. An upgrade guide is included in the docs for anyone migrating from version 3.

Where it fits