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

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 6 years ago
  • Reactions:54
  • Comments:108 (1 by maintainers)

github_iconTop GitHub Comments

80reactions
mgambaticommented, Jun 29, 2018

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.

64reactions
AleskiWebcommented, Apr 12, 2018

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)

Read more comments on GitHub >

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

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