Configure Para client to use MMKV storage in React Native applications
Para’s React Native SDK uses AsyncStorage and Keychain Storage by default. However, you can configure Para to use MMKV for improved performance. This guide shows you how to implement a custom storage solution using the MMKV library.
Create your MMKV storage instance and configure Para to use it:
Copy
Ask AI
import { MMKV } from 'react-native-mmkv';import { ParaMobile } from '@getpara/react-native-wallet@alpha';// Initialize MMKV storage instancesconst storage = new MMKV({ id: 'para-storage'});// Initialize Para client with MMKV storageconst para = new ParaMobile( "YOUR_API_KEY", undefined, { // Custom storage overrides localStorageGetItemOverride: async (key) => { const value = storage.getString(key); return value ?? null; }, localStorageSetItemOverride: async (key, value) => { storage.set(key, value); }, sessionStorageGetItemOverride: async (key) => { const value = storage.getString(key); return value ?? null; }, sessionStorageSetItemOverride: async (key, value) => { storage.set(key, value); }, sessionStorageRemoveItemOverride: async (key) => { storage.delete(key); }, clearStorageOverride: async () => { storage.clearAll(); } });export { para };
The custom storage implementation must handle serialization and deserialization of JSON data. All values are stored as strings, so your implementation should handle converting values correctly.