AsyncStorage.getItem() doesn't seem to work
See original GitHub issueThis 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
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 5 years ago
- Reactions:19
- Comments:35 (11 by maintainers)
Top Results From Across the Web
AsyncStorage.getItem() doesn't seem to work - Stack Overflow
If you want to store data you have to setItem like this: const storeData = async (key, value) => { try { await...
Read more >AsyncStorage.getItem() doesn't seem to work-React Native
[Solved]-AsyncStorage.getItem() doesn't seem to work-React Native. Search. score:1 ... const getData = async key => { try { const data = await AsyncStorage....
Read more >AsyncStorage - React Native
getItem() ... Fetches an item for a key and invokes a callback upon completion. Returns a Promise object. Parameters: Name, Type, Required ......
Read more >API | Async Storage - GitHub Pages
API. getItem . Gets a string value for given key . This function can either return a string value for existing key or...
Read more >What is AsyncStorage in React Native and how to use it with ...
In this case, we only need the string key to refer to the AsyncStorage needed item. In case userId key does not exist...
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 FreeTop 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
Top GitHub Comments
@Krizzu - i still see a reload issue - after reload the storage is not set anymore and returns null. any suggestions?
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.