You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 26, 2022. It is now read-only.
I tried to get a missing key from the storage, but it did not return the default value but null.
I debugged your code and found the issue in the get function. AsyncStorage does not return an error here (API 25, in emulator) but null. So that the returned value is null, not the default Value.
async get(key, defaultValue = null) {
let value = defaultValue;
try {
value = await AsyncStorage.getItem(`${this.__createKey(key)}`);
// value is null here
value = JSON.parse(value);
// still null
} catch (error) {
value = defaultValue;
}
// still null
return value;
}
Hi,
I tried to get a missing key from the storage, but it did not return the default value but
null.I debugged your code and found the issue in the get function. AsyncStorage does not return an error here (API 25, in emulator) but
null. So that the returned value isnull, not the default Value.To fix this you could add a
nullcheck