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>
);
};
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'getItem')
MMKV not initialized before storage call
fixWrap storage initialization inside createJSONStorage(() => mmkvStorage) as shown in docs.
Module not found: Can't resolve 'react-native-mmkv'
Missing peer dependency
fixRun 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)
fixUse import { mmkvStorage } from 'zustand-mmkv-storage'. Audit
Dependencies
zustandrequiredPeer dependency required for the persist middleware
react-native-mmkvrequiredPeer dependency providing the MMKV native module