Skip to content

@stainless-code/persist

Hydration-aware persistence for any reactive store — zero-dep persistSource core; codecs, backends, cross-tab transport, source + framework hydration adapters ship as opt-in recipes

persist-mmkv

47 linesSource

Persist with react-native-mmkv via @stainless-code/persist/backends/mmkv (createMmkvStorage). Sync JSON string-wire; id required; optional MMKV encryptionKey (≤16 bytes).

MMKV backend

Sync backend — no hydrate UI gate required for flash. JSON string-wire. id namespaces the MMKV file. encryptionKey is MMKV's own key (max 16 bytes), not persist-encrypted.

Install

shell
bun add @stainless-code/persist react-native-mmkv

Peer: react-native-mmkv >=4.0.0.

Minimal wiring

ts
import { createMmkvStorage } from "@stainless-code/persist/backends/mmkv";

const storage = createMmkvStorage<Prefs>({ id: "app-prefs" })!;

Common mistakes

  • Gating like IDB — MMKV is sync.
  • Confusing encryptionKey with backends/encrypted.
  • Omitting id.

API surface

  • createMmkvStorage({ id, path?, encryptionKey? }) · mmkvStateStorage(instance)

See also: persist-async-storage; persist-encrypted for WebCrypto AES-GCM.