我正在使用 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)