Different behaviour of LocalStorage and AsyncStorage
See original GitHub issueIn my app, I’m using @react-native-async-storage/async-storage because I plan to support React Native.
But because React Native is not expected to be supported soon, I decided to switch back to LocalStorage
and my app stopped working. If I will add setTimeout to state.dispatchStoreRehydrated();
, it works.
It’s probably because LocalStorage is sync while AsyncStorage isn’t.
onRehydrateStorage: () => (state) => {
if (state)
// Fix for LocalStorage. With AsyncStorage, setTimeout
// is not required.
setTimeout(() => {
state.dispatchStoreRehydrated();
}, 0);
},
Issue Analytics
- State:
- Created 2 years ago
- Comments:35
Top Results From Across the Web
Why AsyncLocalStorage instead of LocalStorage?
AsyncLocalStorage is asynchronous, each local async storage operation you run will be multi-at-a-time. It'll speed up your app's runtime. The ...
Read more >What's Async Local Storage in Node.js v14? - freeCodeCamp
Local storage has been around for awhile," but this time, ... Here's when you use AsyncStorage – storage for asynchronous flows in Node....
Read more >A guide to React Native's AsyncStorage - LogRocket Blog
AsyncStorage is an unencrypted and asynchronous data storage system in React Native that allows users to persist data offline.
Read more >React Native AsyncStorage storing values other than strings
Based on the AsyncStorage React-native docs, I'm afraid you can only store strings.. static setItem(key: string, value: string, ...
Read more >Persist middleware - Zustand Documentation
The persist middleware enables you to store your Zustand state in a storage (e.g. localStorage , AsyncStorage , IndexedDB , etc.
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
LGTM
Thank you for your thorough explanation and the solution you provided. I am closing this issue for now. Maybe I will create a new one with a more specific use case.
As I see it, ideally there should be sync persist and async persist because it’s two different use cases.