AsyncStorage.getItem() doesn't seem to work
See original GitHub issueWhen 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
await AsyncStorage.setItem('foo', 'bar');
await AsyncStorage.getItem('foo').then(console.log); // 'bar'
await AsyncStorage.getAllKeys().then(console.log); // ['foo']
Actual Behavior
await AsyncStorage.setItem('foo', 'bar');
await AsyncStorage.getItem('foo').then(console.log); // null
await AsyncStorage.getAllKeys().then(console.log); // []
Steps to Reproduce
import { AsyncStorage } from 'react-native';
it('should be able to request a value after it was set', async () => {
await AsyncStorage.setItem('foo', 'bar');
const output = await AsyncStorage.getItem('foo');
expect(output).toBe('bar');
});
it('should be able to see a new key after a value was set', async () => {
await AsyncStorage.setItem('foo', 'bar');
const output = await AsyncStorage.getAllKeys();
expect(output).toContain('foo');
});
Issue Analytics
- State:
- Created 6 years ago
- Reactions:54
- Comments:108 (1 by maintainers)
Top Results From Across the Web
AsyncStorage.getItem() doesn't seem to work - Stack Overflow
const setLoginLocal = async loginData => { try { let token = loginData.headers.authorization; let headerToken = ['token', JSON.stringify(token)]; ...
Read more >AsyncStorage.getItem() doesn't seem to work #12 - GitHub
error(error); return false; } return true; }; async function get(key) { try { const value = await AsyncStorage.getItem(key); return JSON.parse( ...
Read more >AsyncStorage.getItem() doesn't seem to work-React Native
getItem() doesn't seem to work -React Native. Search. score:1. Accepted answer. const getData = async key => { try { const data =...
Read more >AsyncStorage - React Native
It is recommended that you use an abstraction on top of AsyncStorage instead of AsyncStorage directly for anything more than light usage since ......
Read more >API | Async Storage - GitHub Pages
Note (legacy): you can use optional callback as an alternative for returned promise. Signature: static getItem(key: string, ...
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
It’s 2 years bug, same with hot reload bug. These bugs are so old that they are mascots for the RN. Now I understand why Airbnb is dropping RN.
Just to add to this, I’ve noticed that if I am using
AsyncStorage.getItem()
and I make a change in a file, to trigger a live reload of the application in the emulator, but then at the same time its recompiling the JS, I then save once again, to interupt and trigger a new compilation, then it stops working and requires me to restart the application (react-native run-android
again)