Skip to content

Storage

Storage

The starter comes with a simple storage module that uses react-native-mmkv to store data in a key-value format. We also added a simple storage utility to assist you in using the storage module.

src/core/storage.tsx
import { MMKV } from 'react-native-mmkv';
export const storage = new MMKV();
export function getItem<T>(key: string): T {
const value = storage.getString(key);
return value ? JSON.parse(value) || null : null;
}
export async function setItem<T>(key: string, value: T) {
storage.set(key, JSON.stringify(value));
}
export async function removeItem(key: string) {
storage.delete(key);
}

The react-native-mmkv library provides various features such as using hooks and adding encryption to stored data. Feel free to check the official docs for more information.

MMKV dev tools plugin

For managing and and monitoring the react-native-mmkv storage instance, we use the MMKV dev tools plugin, which offers us visibility into our storage in real-time. It gives the ability to inspect, add, edit and remove the data manually. To use it, in the terminal press shift + m and choose from the opened list of dev tools the MMKV plugin. The plugin’s web interface will open and display the storage.