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.setItem not working as expected on iOS

See original GitHub issue

Current behavior

Async Storage not working with very basic use case. When I changed my import from using the extracted repo import AsyncStorage from '@react-native-community/async-storage'; to the core repoimport AsyncStorage from 'react-native' it works.

saveFoo(template) {
        AsyncStorage.getItem('savedFoos').then(b => {
            if (b == null) {
                AsyncStorage.setItem('savedFoos', JSON.stringify([template]));
            }
            else {
                var savedFoos = JSON.parse(b);
                savedFoos.push(template);
                AsyncStorage.setItem('savedFoos', JSON.stringify(savedFoos));
            }
        });
    }

Expected behavior

works

nothing was set to asyncstorage. SetItem failed.

Repro steps

above code

Environment

  • Async Storage version: “@react-native-community/async-storage”: “github:react-native-community/async-storage”,
  • React-Native version: RN 60.4
  • Platform tested: iOS
  • Logs/Error that are relevant:

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
jordangrantcommented, Aug 24, 2019

@Krizzu genius. I removed all the import AsyncStorage from 'react-native' from all my files and used only import AsyncStorage from '@react-native-community/async-storage'; across my entire project and now it seems to be working.

1reaction
danipraleacommented, Oct 25, 2019

@jordangrant exactly same issue I had. worked for me too. amazing! I’ve pulled so much hair over it 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

AsyncStorage.setItem not working as expected on iOS #195
Async Storage not working with very basic use case. When I changed my import from using the extracted repo import AsyncStorage from '@react- ......
Read more >
react native Async Storage not working - Stack Overflow
AsyncStorage is asynchronous :-). The committed value isn't available until its returned promise resolves.
Read more >
Async Storage in React Native: How to Do It Right | Waldo Blog
Learn how to implement Async Storage to store data locally in the React Native ... It will start the React Native app on...
Read more >
Asyncstorage React Native | Async Storage Tutorial - YouTube
If you require to get up and running with async storage in your application for ios or android, this video will use the ......
Read more >
A guide to React Native's AsyncStorage - LogRocket Blog
The setItem method saves data to the AsyncStorage and allows a key and a value. Here, the key is a string that the...
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