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.

Installation

First, install the MMKV package:

npm install react-native-mmkv
# or
yarn add react-native-mmkv

Implementation

Create your MMKV storage instance and configure Para to use it:

import { MMKV } from 'react-native-mmkv';
import { ParaMobile, Environment } from '@getpara/react-native-wallet@alpha';

// Initialize MMKV storage instances
const storage = new MMKV({
  id: 'para-storage'
});

// Initialize Para client with MMKV storage
const para = new ParaMobile(
  Environment.BETA, 
  "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.