带有地图功能的异步等待,promise.all 不起作用

pol*_*hmm 5 promise react-native expo

我正在使用 Expo 和 React-Native 构建一个应用程序。

我正在尝试使用 async wait 和 Promise.all 的地图函数从 firebase 加载照片,但我得到的只是一系列未解决的承诺。

renderImages = async () => {
  const images = [];

  if (this.state.images.length > 0) {
    images = this.state.images.map(async (item, index) => {
      const ref = firebase.storage().ref(item);

      var image = await ref.getDownloadURL();

      return (
        <View>
          <Image source={{ uri: image }} />
        </View>
      );
    });

    const imageArray = await Promise.all(images);

    return imageArray || [];
  }

  return (
    <View>
      <Text>STATE.IMAGES.LENGTH is 0</Text>
    </View>
  );
};
Run Code Online (Sandbox Code Playgroud)

我得到的只是

Promise {
  "_40": 0,
  "_55": null,
  "_65": 0,
  "_72": null,
}
Run Code Online (Sandbox Code Playgroud)

pol*_*hmm 2

好吧,所以我不知道async/await总是返回一个promise.

我通过添加这个来解决这个问题

onRenderImages() {
  this.renderImages().then(data => {
     this.setState({ 
         displayImages: data
     })
  })
}
Run Code Online (Sandbox Code Playgroud)