小编pol*_*hmm的帖子

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

我正在使用 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, …
Run Code Online (Sandbox Code Playgroud)

promise react-native expo

5
推荐指数
1
解决办法
870
查看次数

标签 统计

expo ×1

promise ×1

react-native ×1