question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different behaviour of LocalStorage and AsyncStorage

See original GitHub issue

In 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:closed
  • Created 2 years ago
  • Comments:35

github_iconTop GitHub Comments

1reaction
steidacommented, Nov 22, 2021

LGTM

1reaction
steidacommented, Oct 8, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found