Looking better at the MMKV and Zustand, if I'm not wrong, you can simply create a custom store like this:
I'm doing it for React Native, but there many other configs on
zustand's page for other frameworks...
// MMKV.ts
import { MMKV } from 'react-native-mmkv';
const storage = new MMKV({
// ... MMKV configs here ...
});
export default {
setItem: (name: string, value: string) => storage.set(name, value),
getItem: (name: string) => storage.getString(name) ?? null,
removeItem: (name: string) => storage.delete(name)
};
At the persistency's configs object, you can do like this:
import { devtools, persist } from 'zustand/middleware';
// ... Store code here ...
const devtoolsConfig: DevtoolsOptions = {
name: 'my-storage-name',
enabled: process.env.NODE_ENV === 'development'
};
const persistConfig = {
name: 'my-storage-persist-name',
storage: createJSONStorage(() => MMKVStorage),
// or if you want, you can use AsyncStorage instead of MMKV
// storage: createJSONStorage(() => AsyncStorage),
// ... other persist configs here ...
}
const useMyAppStore = create<Store>()(
devtools(
persist((set, get) => ({
// ... Store code here ...
}), persistConfig),
devtoolsConfig
)
);
export default useMyAppStore;
Just a tip: If you're using React Native, it's necessary to adopt JSI Archtecture to use MMKV storage.
I hope this helps.
Let me know if it worked