Retrieve value from AsyncStorage
Retrieve value from AsyncStorage
Additional information
- In this case, we only need the string key to refer to the AsyncStorage needed item. In case userId key does not exist in AsyncStorage (i.e. the first time the app loads), the function will return undefined or in the example above the string 'none'.
Const getUserId = async () => {
let userId = '';
try {
userId = await AsyncStorage.getItem('userId') || 'none';
} catch (error) {
// Error retrieving data
console.log(error.message);
}
return userId;
}
Semantic portal