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.

Async storage lookup/default value issue

See original GitHub issue

@astoilkov: A React app can have a query parameter (e.g. ?appId=123) which is persisted using this use-local-storage-state hook. A default value is also set (-1). When the state is -1, an error is thrown (no App ID is set, the app needs an App ID to function). The problem is that the use-local-storage-state is asynchronous: In the first render the value is still the default value (-1), in the 2nd render the value is the one retrieved from local storage. This means that in the first render the app already shows an error message, as the error will also stop further renders.

How can I get around this?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
astoilkovcommented, Mar 14, 2022

Hmm. I can’t seem to replicate the issue. Here is the CodeSandbox I’ve experimented with: https://codesandbox.io/s/todos-example-use-local-storage-state-forked-s03chx?file=/src/App.tsx. Can you modify it in order to replicate the problem?

2reactions
astoilkovcommented, Mar 14, 2022

I think your case will be fixed when https://github.com/astoilkov/use-local-storage-state/commit/762fe4f413d5bd0805eab7e8e22bf1b0875d7218 lands in v16. I will write here when that happens so you can test it. How does that sound?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set default value and if not then the ... - Stack Overflow
I am using the async storage to get the value of recent. If the value is not found in async storage then I...
Read more >
API | Async Storage - GitHub Pages
Sets a string value for given key . This operation can either modify an existing entry, if it did exist for given key...
Read more >
AsyncStorage - React Native
On iOS, AsyncStorage is backed by native code that stores small values in a serialized dictionary and larger values in separate files. On ......
Read more >
util.AsyncStorage. Developer's guide - Yandex
Search on a map ... AsyncStorage. Extends util.Storage. Storage that provides asynchronous access to key values. ... Parameter, Default value, Description ...
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 >

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