【发布时间】:2019-11-05 07:57:06
【问题描述】:
我正在使用 expo 和 react-native 构建一个应用程序。
我正在尝试使用 async await 和使用 Promise.all 的 map 函数从 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>
);
};
我得到的只是
Promise {
"_40": 0,
"_55": null,
"_65": 0,
"_72": null,
}
【问题讨论】:
-
这看起来不像一个promise数组,它看起来像一个promise。是的,
renderImages是一个async function,所以它当然会返回一个承诺。一切似乎都在工作。您能否向我们展示您在哪里调用该函数的代码,以及您在哪里“取回”该结果?
标签: react-native promise expo