Right way to setItem in AsyncStorage

前端 未结 4 1022
萌比男神i
萌比男神i 2021-02-15 16:57

I want to use AsyncStorage.setItem inside AsyncStorage.getItem. How to do that in right way?

My code is as follows:

createVehic         


        
4条回答
  •  离开以前
    2021-02-15 17:22

    Please refer to this official document, it uses getItem inside setItem, So I think you could also use setItem inside getItem, because the return value is just a Promise for both getItem and setItem.

    AsyncStorage.setItem('UID123', JSON.stringify(UID123_object), () => {
      AsyncStorage.mergeItem('UID123', JSON.stringify(UID123_delta), () => {
        AsyncStorage.getItem('UID123', (err, result) => {
          console.log(result);
        });
      });
    });
    

提交回复
热议问题