Guides
Storage
Storage guide with the react-native-mmkv library.
Caracal ships with a simple storage module built on react-native-mmkv, a fast key-value store for React Native. A thin utility wrapper lives at src/lib/storage.tsx to keep usage ergonomic and type-safe across the codebase.
Storage Utilities
The wrapper at src/lib/storage.tsx exports three helpers:
getItem<T>(key)— reads and JSON-deserializes a value; returnsnullif absentsetItem<T>(key, value)— JSON-serializes and writes a valueremoveItem(key)— deletes a key
These are used throughout Caracal for token persistence, user preferences, and language selection.
import { MMKV } from 'react-native-mmkv';
export const storage = new MMKV();
export function getItem<T>(key: string): T | null {
const value = storage.getString(key);
return value ? (JSON.parse(value) as T) : null;
}
export function setItem<T>(key: string, value: T): void {
storage.set(key, JSON.stringify(value));
}
export function removeItem(key: string): void {
storage.delete(key);
}Why MMKV?
- Synchronous: No
async/awaitneeded — reads and writes are instant - Fast: Roughly 30× faster than AsyncStorage
- Encrypted: Supports AES encryption for sensitive data
- Hook support:
react-native-mmkvexposes reactive hooks for live value subscriptions
See the official MMKV docs for encryption setup, hooks, and advanced configuration.