Reputation: 2087
Issue Description::
I'm working on react-native application. I am getting user information from local storage, but some time it's return undefined. This working fine on debug mode, only problem in release mode.
Code::
let currentUser = await AsyncStorage.getItem("CURRENT_USER");
let user = JSON.parse(currentUser);
Version::
"react": "^16.8.4",
"react-native": "^0.58.6"
Upvotes: 0
Views: 138
Reputation: 643
Your code should return a stored string if you have setItem
earlier or null if you didn't. I don't know why the need for JSON.parse
.
How about this:
async getUser() {
let user = null;
AsyncStorage.getItem("CURRENT_USER")
.then((result) => {
if (result !== null) {
user = result;
}
});
return user;
}
Upvotes: 1