64
rated 0 times
[
65]
[
1]
/ answers: 1 / hits: 24531
/ 7 Years ago, mon, may 22, 2017, 12:00:00
I'm trying to check whether a key is available in AsyncStorage
with AsyncStorage.getItem('key_name')
. If the key is not available it is not returning null, it still returns following promise object:
Promise
_45:0
_54:null
_65:null
_81:1
My function for getting data is as bellow:
checkItemExists(){
let context = this;
try {
let value = AsyncStorage.getItem('item_key');
if (value != null){
// do something
}
else {
// do something else
}
} catch (error) {
// Error retrieving data
}
}
How can I check whether a key exists in AsyncStorage or not?
More From » react-native