Skip to content

MMKV StorageFast key-value storage for React Native

Built on Tencent's MMKV and JSI. Any data type, any number of databases, with or without encryption.

react-native-mmkv-storage

Install ​

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

Read and write ​

js
import { MMKVLoader } from 'react-native-mmkv-storage';

const storage = new MMKVLoader().initialize();

storage.setString('user', 'ammar');
storage.setInt('age', 24);
storage.setMap('settings', { theme: 'dark' });

storage.getString('user'); // => "ammar"
storage.getMap('settings'); // => { theme: "dark" }

Keep components in sync ​

jsx
import { MMKVLoader, useMMKVStorage } from 'react-native-mmkv-storage';
import { Text, TouchableOpacity } from 'react-native';

const storage = new MMKVLoader().initialize();

export default function Profile() {
  const [user, setUser] = useMMKVStorage('user', storage, 'anonymous');

  return (
    <TouchableOpacity onPress={() => setUser('ammar')}>
      <Text>{user}</Text>
    </TouchableOpacity>
  );
}

Any write to user — from this component, another component, or plain non-React code — updates every hook watching that key.

Encrypt a database ​

js
import { MMKVLoader } from 'react-native-mmkv-storage';

const secure = new MMKVLoader().withInstanceID('secure').withEncryption().initialize();

secure.setString('token', 'a-secret-value');

The encryption key is generated for you and stored in the Keychain or Keystore, then retrieved automatically on the next launch.

Supported React Native versions ​

ArchitectureReact Native
New architecture0.75+, tested up to 0.87
Old architecture0.71+

Codegen specs are generated by your app at build time, so the library always compiles against the React Native version your app uses.

Released under the MIT License.