Caracal Starter
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; returns null if absent
  • setItem<T>(key, value) — JSON-serializes and writes a value
  • removeItem(key) — deletes a key

The shared instance is created with createMMKV() and uses the default unencrypted storage. The helpers persist the demo session and accounts. Preference hooks also use MMKV directly.

Keys used by the starter

KeyWritten byContents
accountssrc/lib/auth/accounts.tsLocal accounts: id, full name, email, salt and password hash
sessionsrc/lib/auth/utils.tsx{ userId } of the signed-in account
IS_FIRST_TIMEuseIsFirstTime()Whether onboarding was completed
SELECTED_THEMEuseSelectedTheme()light, dark or system
localuseSelectedLanguage()en or vi

Passwords are only ever stored as a salted SHA-256 hash, never in plain text.

Why MMKV?

  • Synchronous: No async/await needed — reads and writes are instant
  • Hook support: react-native-mmkv exposes reactive hooks for live value subscriptions

See the official MMKV docs for encryption setup, hooks, and advanced configuration.

On this page