AsyncStorage setItem and getItem confusion
I mainly used shorthand to pull some data from Firebase and you need a way to get that data even if nextProps is not being fed into it. this.state is cleared when the screen is redisplayed. I thought I'd give an asynchronous shot (not sure if this is the correct use case ???)
Here is my code:
_loadInitialState = (nextProps) => {
AsyncStorage.setItem('currentListing', JSON.stringify(nextProps));
}
_renderInitialState = async () => {
try {
const value = await AsyncStorage.getItem('currentListing');
if (value !== null){
// We have data!!
return JSON.parse(value);
}
} catch (error) {
// Error retrieving data
}
}
This is what I get when I _renderInitialState:
{"_40":0,"_65":1,"_55":{"selectedListing":{"listingAttributes":{"avgRating":0,"bio":"Hey","bodyType":"Meso","category":"Endurance","experience":"Btbtt","gender":"Male","location":"somewhere","media":"lmao","name":"Josh","price":"23456","userId":"KruIzhLvPTctEoo8HZWQ2ell4ro2"}}},"_72":null}
Why are my keys in numbers, I thought "currentListing" was supposed to be my key that I set? How to get results from the key now?
+3
source to share
No one has answered this question yet
Check out similar questions: