persist with sync storage
See original GitHub issueHi,
I’m using react-native-mmkv as a replacement to asyncstorage,
react-native-mmkv is a sync library, but when using it in the persist middlewar, it doesn’t rehydrate.
This is what I had to write to get it to work
export const storage: StateStorage = {
getItem: async (key: string): Promise<string | null> => {
const reply = MMKV.getString(key)
return Promise.resolve(reply ?? null)
},
setItem: async (key: string, value: string): Promise<void> => {
MMKV.set(key, value)
Promise.resolve()
},
}
but ideally, it should work synchronously
export const storage: StateStorage = {
getItem: (key: string): string | null => {
const reply = MMKV.getString(key)
return reply ?? null
},
setItem: (key: string, value: string): void => {
MMKV.set(key, value)
},
}
}
I’ve read a bit about the issue here and I was wondering it https://github.com/pmndrs/zustand/pull/455 fixes the issue, or maybe I should look elsewhere for a fix ?
Issue Analytics
- State:
- Created 2 years ago
- Comments:14
Top Results From Across the Web
console.error: "redux-persist failed to create sync storage ...
In redux-persist v6, you try changing as follows: Old config V5 => import storage from 'redux-persist/lib/storage'; const persistConfig ...
Read more >redux-persist failed to create sync storage. falling back to noop ...
I have configured redux-perist in my React.js application like below. While launching application, I am getting below error in console.
Read more >redux-persist failed to create sync storage. falling back to noop ...
Fixed code for nextjs:mightycoders.xyz/redux- persist -failed-to-create- sync - storage -falling-back-to-noop...
Read more >storage.sync - Mozilla - MDN Web Docs
Represents the sync storage area. Items in sync storage are synced by the browser. The data is then available on all instances of...
Read more >chrome.storage - Chrome Developers
The Storage API provides an extension-specific way to persist user data and state. ... Local and sync storage areas should not store confidential...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for that link @AnatoleLucet, I’m not sure how I’d use
hasHydrated
in my case since what I want to do is call a function on the state once hydration has been finished, and that only seems to allow me to check if it’s been finished. I also tried to subscribe toonFinishHydration
but wasn’t able to get that to work, I’m guessing because I was subscribing to it too late and hydration was already done.But, I did read more into that and learned that sync storage is actually finished when the state is created, so in my case I just switched to calling the function on the state I wanted directly in my splash screen component instead of waiting for hydration and trying to call it in
onRehydrateStorage
/setting my ownhydrated
prop on the state, and now it’s working fine.The error param is not set in
onRehydrateStorage
if that’s what you meant.I’ll try a clean cache, etc. and retry
setRehydrated
, to check if it was something odd happening.