Async Storage does not persist between app reloads
expect the storage to persist between app reloads
Theory: It may be due to my environment. I am on RN 0.60.3 but link async-storage manually instead of relying on the auto-linking mechanic. Could this cause an issue?
Steps to reproduce:
await AsyncStorage.setItem('someItem', JSON.stringify(someItem));let keys = [];
try {
keys = await AsyncStorage.getAllKeys();
} catch (e) {
console.log('e', e);
// read key error
}
console.log(keys);
let keys = [];
try {
keys = await AsyncStorage.getAllKeys();
} catch (e) {
console.log('e', e);
// read key error
}
console.log(keys);
do not use podfile, instead link react-native manually
"@react-native-community/async-storage": "^1.6.1"
"react-native": "0.60.3"
I too am experiencing this issue the last few days - but only on iOS simulator (iOS 12.4). I only experience this intermittently when using cmd+R to reload the app on the simulator. When I press cmd+D then click "Reload" in the simulator I never lose my AsyncStorage data?!
"@react-native-community/async-storage": "^1.6.1"
"react-native": "0.60.4"
Hello,
I also had this problem before finally realizing that I was still importing the package from react-native in some places. It turns out that this created conflicts between the different libraries on IOS.
I hope this could help you in some way.
@ElieMyIdea 鈽濓笍 Yes, this fixed my issue after changing all usage/imports to use this package only. Thanks for mentioning 馃憤
If anyone is still experiencing, it may be related to a dependency lib using the legacy react-native import too.
Thanks @ElieMyIdea That seems to be the case for me as well.
@crobinson42 I am also finding that my dependencies using the old import may be causing some of the issues too.
I'm using:
"@react-native-community/async-storage": "^1.6.1",
"react-native": "0.60.4",
and still have this error. I've checked and everywhere I was importing AsyncStorage from "@react-native-community/async-storage" (I use it only once to save and once to get value). Now I'm back to importing it from "react-native" and it's working, but this is temporary fix.
@MariuszSpeednet
Probably one of your dependency is still using Async Storage from the core - there's a condition race if that's the case. You can read more about it here
@Krizzu
Thanks! It was redux-persist. It seems that I need to set store manually to AsyncStorage.
Most helpful comment
I too am experiencing this issue the last few days - but only on iOS simulator (iOS 12.4). I only experience this intermittently when using
cmd+Rto reload the app on the simulator. When I presscmd+Dthen click "Reload" in the simulator I never lose my AsyncStorage data?!"@react-native-community/async-storage": "^1.6.1"
"react-native": "0.60.4"