Skip to content

AsyncStorage.setItem not working as expected on iOS #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jordangrant opened this issue Aug 24, 2019 · 6 comments
Closed

AsyncStorage.setItem not working as expected on iOS #195

jordangrant opened this issue Aug 24, 2019 · 6 comments

Comments

@jordangrant
Copy link

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:
@MangalBeta
Copy link

MangalBeta commented Aug 24, 2019

same error on IOS
AsyncStorage.setItem not working as expected on RN 0.60

@MangalBeta
Copy link

working
Check below changes is store file

import storage from 'redux-persist/lib/storage';
to
import AsyncStorage from '@react-native-community/async-storage';
and set storage =>
const persistConfig = {
key: 'root',
storage:AsyncStorage,
timeout: null,
};

@krizzu krizzu added the LEGACY label Aug 24, 2019
@krizzu
Copy link
Member

krizzu commented Aug 24, 2019

@jordangrant
Is any of your dependency using Async Storage from the RN core? It looks like it does and race condition is happening in place.

@jordangrant
Copy link
Author

@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.

@krizzu
Copy link
Member

krizzu commented Aug 24, 2019

Please checkout my comment about it here

@danipralea
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants