JSPM

  • Created
  • Published
  • Downloads 395091
  • Score
    100M100P100Q182143F
  • License MIT

An efficient, small mobile key-value storage framework developed by WeChat. Works on Android and iOS.

Package Exports

  • react-native-mmkv

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-mmkv) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

MMKV

MMKV is an efficient, small mobile key-value storage framework developed by WeChat.

See Tencent/MMKV for more information

Features

  • Get and set strings, booleans and numbers
  • Synchronous calls, no async/await, no Promises.
  • High performance because everything is written in C++ (even the JS functions have C++ bodies!)
  • JSI
  • No bridge traffic

Fun fact: since all the JS functions have C++ implementations, you can also directly call them in reanimated worklets

Benchmark

AsyncStorage vs MMKV: Reading a value from Storage 1000 times.
Measured in milliseconds on an iPhone 8, lower is better.

Installation

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

Usage

Set

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

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

Get

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

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

Delete

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

MMKV.delete('user.name')

Get all keys

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

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

Objects

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

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

MMKV.set(JSON.stringify(user), 'user')

const jsonUser = MMKV.getString('user') // { 'username': 'Marc', 'age': 20 }
const userObject = JSON.parse(jsonUser)

Contributing

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

License

MIT