React Native AsyncStorage returns promise instead of value

前端 未结 2 1649
难免孤独
难免孤独 2021-02-09 05:20

I understand this is a very common problem in RN and I am still trying to understand the very possible advantage of returning a promise when loading data from a property file in

2条回答
  •  花落未央
    2021-02-09 06:12

    the thing is await turns the promise into a value, you don't need to use .then(). Try the following:

    const keys = await AsyncStorage.getAllKeys()
    const values = await AsyncStorage.multiGet(keys)
    
    // at this point `values` will have data for all keys 
    

提交回复
热议问题