AsyncStorage.getItem returns undefined : React Native

后端 未结 2 1930
闹比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:22

    I actually copied the object from one to another. It worked.

    AsyncStorage.getItem('listobject').then((obj) => {
        if(obj == undefined)
        {
            var obj1 ={};
            obj1.data ={};
            obj1.data.isdirty = true;
            console.log("obj1 = "+ JSON.stringify(obj1));
            AsyncStorage.setItem('listobject',obj1);
            obj = obj1; //THIS IS WHAT I DID!
            console.log("obj = "+ JSON.stringify(obj));
        }
        if(obj.data.isdirty)
        {
            obj.data.isdirty = false;
            AsyncStorage.setItem('listobject',JSON.stringify(obj));
            return AsyncStorage.getItem('listobject');
        }
    }).done();
    

提交回复
热议问题