Registry / database / zustand-mmkv-storage

zustand-mmkv-storage

JSON →
library1.0.0jsnpmunverified

Fast MMKV storage adapter for Zustand persist middleware in React Native. Current stable version is 1.0.0. Provides a lightweight, lazy-loading adapter that leverages react-native-mmkv for synchronous, high-performance storage (approximately 30x faster than AsyncStorage). Key differentiators include built-in instance caching, full TypeScript support, hydration handling to prevent flash of initial state, and compatibility with both bare React Native and Expo. The package has zero runtime dependencies beyond its peers (zustand and react-native-mmkv).

npm install zustand-mmkv-storage
INSTALL
IMPORT
SIG · ZUSTAND-MMKV-STORA
Z
zustand-mmkv-storage
databasejavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mmkvStorage
import { mmkvStorage } from 'zustand-mmkv-storage'
import mmkvStorage from 'zustand-mmkv-storage'
Default import is wrong; mmkvStorage is a named export.
createMMKVStorage
import { createMMKVStorage } from 'zustand-mmkv-storage'
import { createMMKVStorage } from 'zustand-mmkv-storage/default'
createMMKVStorage is exported directly from the package root, not a subpath.
MMKV
import { MMKV } from 'react-native-mmkv'
import { MMKV } from 'zustand-mmkv-storage'
MMKV is from react-native-mmkv, not from zustand-mmkv-storage.

Complete example of Zustand store with MMKV persistance and hydration handling

// src/stores/bearStore.ts import { create } from "zustand"; import { persist, createJSONStorage } from "zustand/middleware"; import { mmkvStorage } from "zustand-mmkv-storage"; interface BearState { bears: number; increase: () => void; hasHydrated: boolean; } export const useBearStore = create<BearState>()( persist( (set) => ({ bears: 0, increase: () => set((state) => ({ bears: state.bears + 1 })), hasHydrated: false, }), { name: "bear-storage", storage: createJSONStorage(() => mmkvStorage), onRehydrateStorage: () => (state) => { if (state) { state.hasHydrated = true; } }, } ) ); // src/components/BearCounter.tsx import { View, Text, Button, ActivityIndicator } from "react-native"; import { useBearStore } from "../stores/bearStore"; const BearCounter = () => { const { bears, increase, hasHydrated } = useBearStore(); if (!hasHydrated) return <ActivityIndicator size="large" />; return ( <View> <Text>Bears: {bears}</Text> <Button title="Add bear" onPress={increase} /> </View> ); };
Debug
Known issues
gotchaMMKV requires native build step; not supported in Expo Go or web without custom dev client
fix
Use 'expo prebuild' or a bare React Native workflow. For Expo, refer to react-native-mmkv setup guide.
affects: >=1.0.0
gotchaStorage key collisions if multiple stores use the same name
fix
Ensure each persist store has a unique 'name' field.
affects: >=1.0.0
deprecatedNo deprecated patterns known yet, but watch for future versions.
fix
N/A
affects: >=1.0.0
gotchahydrate on App startup with default storage may show stale UI
fix
Use onRehydrateStorage to set a hydration flag (see quickstart).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'getItem')
MMKV not initialized before storage call
fix
Wrap storage initialization inside createJSONStorage(() => mmkvStorage) as shown in docs.
Module not found: Can't resolve 'react-native-mmkv'
Missing peer dependency
fix
Run npm install react-native-mmkv and rebuild or configure Expo native modules.
TypeError: (0 , zustand_mmkv_storage_1.mmkvStorage) is not a function
Wrong import (default import instead of named)
fix
Use import { mmkvStorage } from 'zustand-mmkv-storage'.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
zustandrequiredPeer dependency required for the persist middleware
react-native-mmkvrequiredPeer dependency providing the MMKV native module
Agent activity
62 hits · last 30 days
node
54
OpenAI (training)
1
Resources
zustand-mmkv-storage — npm install zustand-mmkv-storage · libregistry