AsyncStorage.getItem returns undefined : React Native

后端 未结 2 1914
闹比i
闹比i 2021-01-06 07:46

Codeflow is-

I am checking if an entry called listobject exists in the AsyncStorage.

  1. If it doesn\'t exist, then, I create an object,

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-06 08:12

    I'm not quite following the entire question I do however see an issue with the use AsyncStorage. Going by the name, Async implies that the operations are asynchronous. So when you do getItem(key), you should either pass in a callback or use the Promise object it returns as you are doing in the first line of code.

    obj = AsyncStorage.getItem('listobject'); console.log("obj = "+ JSON.stringify(obj));

    obj is going to be the Promise in this case.

    Then if you check on obj for the presence of a data and isDirty child property, they will not exist on the Promise.

提交回复
热议问题