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.

AsyncStorage.getItem() doesn't seem to work

See original GitHub issue

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

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:closed
  • Created 5 years ago
  • Reactions:19
  • Comments:35 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
royischcommented, Apr 11, 2019

@Krizzu - i still see a reload issue - after reload the storage is not set anymore and returns null. any suggestions?

4reactions
joshjhargreavescommented, Feb 27, 2019

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.

Read more comments on GitHub >

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

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