-
Notifications
You must be signed in to change notification settings - Fork 473
AsyncStorage.getItem() doesn't seem to work #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We recently saw issues with this in our app on a large number of android devices when doing something very similar to the above in production but we had issues reproducing locally. Very happy to help do the work necessary to fix this. Would be great to use this thread to maybe identify what's causing the issue and different approaches we could use to fix. |
Maybe an author get null because use of mock implementation: |
Thanks for your time. Does the issue exist while developing the app? |
I have the same issue, but found a way to make it work with We have a separate helper class called
These were working just fine by utilizing them like this: Then, I added a new one. I followed the exact same patterns, just changing the name and all of a sudden this same way of getting the value for this The only way I was able to get the value for
Not as ideal, but hope it may help someone. |
@krizzu Sorry that may have been confusing to use I edited the previous post to change I think it might have just been a misunderstanding on my end as I am very familiar with using a |
v1.3.0 released, please check it out 🙏 |
@krizzu - i still see a reload issue - after reload the storage is not set anymore and returns null. any suggestions? |
@royisch hey, Can you elaborate bit more? Is in within tests? |
yes. I set using asyncStorage.set, for testing purposes i verified that the data is persisted, so i fetch it back - all looks good. When i reload the same key i get null. My question is - should i revert to react-native implementation for now? as my application is waiting to be released. |
@royisch Also, did you clean packager's cache, reinstalled the app/linked module properly? |
Hi @krizzu i mean |
hi @krizzu i cleaned the cache also. Im using RN 0.59 and installed Not sure what the next step is here. Thanks |
@royisch Additional steps to consider:
Or remove |
Hi @krizzu, did all of it, not sure what the next step is. I will try to completely re-install the library again. |
@royisch I believe that something in your implementation is causing to (maybe) override values in Async Storage (or calling I'm closing this issue, if you'll need more help, please open new issue with provided repro steps. thanks. |
For what it's worth, I'm seeing similar behavior, where a value I set is null upon refreshing the app. I'm also using |
@npedrini - i think i have a solution, you can pass as a configuration to redux-offline the storage you want to use, probably you should import the storage from the new AsyncStorage and pass it as a parameter. |
@never00miss I can confirm that passing |
I get a similar issue as @npedrini above. I also use redux-persist and I recently reverted it to using the RN version as I was having issues with this library not correctly rehydrating the state. I was also using this library in a separate part of the code and noticed it was always returning null. Reverting that code to use the RN core version also fixed the issue. I've just tried updating all occurrences of AsyncStorage to the RNC version 1.5.1 and it seems to be working now. |
Actually 1.5.1 does not fix the issue. I'll be reverting to using AsyncStorage from RN core. |
Having the same issue. Why is this closed? I am on react-native version 0.59.10 and on version 1.5.1 of asynch storage |
@MakhouT facebook/react-native#18372 (comment) might help (if you have control over the AsyncStorage code in your project).
|
Investigated a bit more, and the issue isn't async-storage issue. It was react-native-debugger that doesn't instantly show the result when saving an item. I had to refresh the app to see the item in the debugger. Works as expected currently. |
Just a bit related or unrelated, I was investigating similar problem. The await was hanging at the AsyncStorage. However debugging more, revealed it was hanging on any Promise at application startup. ASyncStorage just seemed to be one of the first during init. Now the problem was then narrowed down to completely different package (in this case it was @storybook/react-native). Reason for the hang is still mystery, but I suspect it is related somehow incompatible React Native versions being used in two different packages and causing some strange internal conflict which does not show up other than hanging Promises. Lesson learned, make sure packages are compatible. Also some init code should be run after the React Native has initialized itself, so either use useEffect in your App component or use AppRegistry to time the initialization code instead of running it in the import file's root. |
I'm still encountering this issue. I set a token after logging in, and can access it after it's been set:
After reloading the app, Not using I'm using React Native v0.59.5 and @react-native-community/async-storage v1.3.3. |
@jckw We are experiencing similar issue in our app. We haven't been able to reproduce the error ourselves, but we have customers from time to time complaining they have to login again (meaning the token was lost). |
@Cellule @jckw Can you see a yellow box warning about They're working on the same files/preferences and the way they do might cause the issue you have. Please refer to my comment about it in another issue. |
Ah amazing! Had to patch a few packages we're using that used the old version of AsyncStorage, but now that warning it gone and it seems to have solved the issue. Thank you! |
I found solution for this |
On Android, I had the issue where Updated link: https://react-native-community.github.io/async-storage/docs/advanced/executor |
I have the same issue in production for some android device, it looks odd that it works on some and on others not. |
This issue was originally created by @mrded as facebook/react-native#18372.
When I try to set a value via
AsyncStorage.getItem()
, I cannot request it back.Environment
Environment:
OS: macOS High Sierra 10.13.3
Node: 9.8.0
Yarn: 1.5.1
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: Not Found
Packages: (wanted => installed)
react: ^16.3.0-alpha.1 => 16.3.0-alpha.1
react-native: 0.54.0 => 0.54.0
Expected Behavior
Actual Behavior
Steps to Reproduce
The text was updated successfully, but these errors were encountered: