{"library":"react-native-mmkv","title":"React Native MMKV Storage","description":"react-native-mmkv is a high-performance, persistent key-value storage solution for React Native applications. It leverages Tencent's MMKV library, which is written in C++ and optimized for speed, providing significantly faster read/write operations compared to AsyncStorage. The current stable version is 4.3.1. The library maintains a rapid release cadence, with multiple minor and patch releases occurring monthly, indicating active development and responsiveness to bug fixes and feature enhancements. Key differentiators include its raw speed, native implementation via Nitro, and seamless integration with both old and new React Native architectures, supporting various data types efficiently. Version 4.x introduced a complete rewrite using Nitro and now integrates `MMKVCore` through native dependency managers like CocoaPods and Gradle, simplifying its native setup.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install react-native-mmkv"],"cli":null},"imports":["import { MMKV } from 'react-native-mmkv'","import { useMMKVStorage } from 'react-native-mmkv'","import { MMKVLoader } from 'react-native-mmkv'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { MMKV } from 'react-native-mmkv';\n\nconst storage = new MMKV();\n\n// Set values\nstorage.set('user.name', 'John Doe');\nstorage.set('user.age', 30);\nstorage.set('isLoggedIn', true);\nstorage.set('lastLoginTimestamp', Date.now());\n\nconst settings = { theme: 'dark', notifications: true };\nstorage.set('appSettings', JSON.stringify(settings));\n\n// Get values\nconst userName = storage.getString('user.name');\nconst userAge = storage.getNumber('user.age');\nconst isLoggedIn = storage.getBoolean('isLoggedIn');\nconst lastLogin = storage.getNumber('lastLoginTimestamp');\nconst appSettingsString = storage.getString('appSettings');\nconst appSettings = appSettingsString ? JSON.parse(appSettingsString) : {};\n\nconsole.log(`User: ${userName}, Age: ${userAge}, Logged In: ${isLoggedIn}`);\nconsole.log(`App Settings: ${JSON.stringify(appSettings)}`);\n\n// Delete values\nstorage.delete('user.age');\nconsole.log('User age after deletion:', storage.getNumber('user.age')); // Should be undefined or default\n\n// Clear all data\n// storage.clearAll();\n// console.log('All data cleared:', storage.getAllKeys());\n\n// Example with encrypted storage (requires a separate 'id')\nconst encryptedStorage = new MMKV({ id: 'my-encrypted-storage', encryptionKey: process.env.MMKV_ENCRYPTION_KEY ?? 'my-secret-key' });\nencryptedStorage.set('secretData', 'This is a secret!');\nconsole.log('Encrypted data:', encryptedStorage.getString('secretData'));","lang":"typescript","description":"This quickstart demonstrates how to initialize an MMKV storage instance, store various data types (string, number, boolean, JSON objects), retrieve them, and delete specific keys. It also includes an example of setting up an encrypted storage instance.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}