AsyncStorage setItem和getItem混淆

时间:2017-07-08 15:02:45

标签: reactjs react-native

基本上我使用redux从Firebase中提取一些数据,并且即使没有nextProps也需要一种方法来检索这些数据。当屏幕重新渲染时,this.state会被清除。我以为我会给异步存储器一个镜头(不确定这是否是正确的用例???)

这是我的代码:

 _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
}
    }

这是我在_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}

为什么我的钥匙在数字上,我认为' currentListing'应该是我设置的关键?如何从密钥中检索结果?

0 个答案:

没有答案