unstorage-sync-react-native-mmkv
v0.1.1
Published
unstorage-sync driver for react-native-mmkv
Maintainers
Readme
unstorage-sync-react-native-mmkv
unstorage-sync driver for react-native-mmkv.
Install
npm install unstorage-sync-react-native-mmkv unstorage-sync react-native-mmkv
# peer: react-native-nitro-modules (required by react-native-mmkv)Usage
import { createSyncStorage } from "unstorage-sync";
import { mmkvDriver } from "unstorage-sync-react-native-mmkv";
const storage = createSyncStorage({
driver: mmkvDriver({ id: "app-storage" }),
});
storage.setItem("foo:bar", { hello: "world" });
storage.getItem("foo:bar"); // → { hello: "world" }Options
mmkvDriver accepts the same options as createMMKV (id, path, encryptionKey, …), plus:
createMMKV— optional factory override (defaults toreact-native-mmkv'screateMMKV). Use this to inject an SSR-safe wrapper.
Defaults:
id:"mmkv.default"compareBeforeSet:true
Access the MMKV instance
const driver = mmkvDriver({ id: "app-storage" });
const mmkv = driver.getInstance!();Watching
Native MMKV change listeners are forwarded to storage.watch / driver.watch:
const unwatch = storage.watch((event, key) => {
console.log(event, key); // "update" | "remove"
});