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));
}
});
}
works
nothing was set to asyncstorage. SetItem failed.
above code
same error on IOS
AsyncStorage.setItem not working as expected on RN 0.60
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,
};
@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.
@Krizzu genius. I removed all the import AsyncStorage from 'react-native' from all my files and used onlyimport AsyncStorage from '@react-native-community/async-storage'; across my entire project and now it seems to be working.
Please checkout my comment about it here
@jordangrant exactly same issue I had. worked for me too. amazing! I've pulled so much hair over it 馃憤
Most helpful comment
@Krizzu genius. I removed all the
import AsyncStorage from 'react-native'from all my files and used onlyimport AsyncStorage from '@react-native-community/async-storage';across my entire project and now it seems to be working.