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.

Unable to get any item with `getItem`

See original GitHub issue

Current behavior

Unable to retrieve values with getItem

When using the following code:

import AsyncStorage from '@react-native-async-storage/async-storage';

  let storageKey = 'persist:root';
  console.log("Getting stored state", storageKey);
  (async () => {
    console.log('about to call async');
    try {
      let res = await AsyncStorage.getItem('persist:root');
      console.log("res", res);
    } catch(e) {
      // error reading value
      console.log(e);
    }
  })();

  console.log("passed here");
  AsyncStorage.getAllKeys((err, keys) => {
    AsyncStorage.multiGet(keys, (error, stores) => {
      stores.map((result, i, store) => {
        console.log({ [store[i][0]]: store[i][1] });
        return true;
      });
    });
  });

The top chunk never prints out an error or a result. I just get:

Getting stored state persist:root
about to call async
passed here

It just continues onto the bottom chunk where it correctly prints values:

{"persist:root": ...}

Expected behavior

The item should be returned when using await AsyncStorage.getItem('persist:root')

Repro steps

See above.

Environment

  • Platforms tested:
    • Android
    • iOS
    • macOS
    • Windows
  • AsyncStorage version: ^1.15.4
  • Environment:
System:
    OS: macOS 11.2.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 24.73 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.18.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.3.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK:
      API Levels: 26, 28, 29
      Build Tools: 28.0.3, 29.0.2, 29.0.3
      System Images: android-28 | Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.6010548
    Xcode: 12.5/12E262 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_242 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1
    react-native: 0.64.1 => 0.64.1
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
  • Logs/Errors that may be relevant:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
jpolocommented, Jun 10, 2021

For our case, it seems metro inlineRequires: true is triggering the bug. inlineRequires: false (in metro.config.js) is OK. Pretty high tradeoff to pay to make this work…

2reactions
EricWienercommented, Jul 7, 2021

Created issue https://github.com/facebook/metro/issues/682. Could everyone please vote/comment on it to get it some attention

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: GetItem (single item) condition if not found
Solved: Hello, I have a SharePoint list, and a flow that should add items or update it if already exists.... I see solutions...
Read more >
javascript - Unable to get item from local storage
I think the problem is regarding first-time page load failing to retrieve the data with useSelector hook. I think you need to change...
Read more >
Unable to fetch item using getitem method
I tried to fetch using Id and path also. And checked the connection strings as well. Does the SOAP service need to have...
Read more >
Storage.getItem() - Web APIs - MDN Web Docs
The getItem() method of the Storage interface, when passed a key name, will return that key's value, or null if the key does...
Read more >
GetItem - Amazon DynamoDB
The GetItem operation returns a set of attributes for the item with the given primary key. If there is no matching item, GetItem...
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