i am trying to fetch all images in firebase storage. So far it works. But the problem is how to put ALL data inside array in asynchronous function and not just one then pass it into state?
My Code :
async componentDidMount(){
auth().signInAnonymously();
var arr = [];
var storageRef = storage().ref("/madu_mubarak/");
await storageRef.listAll().then((result)=> {
result.items.forEach((imageItem) =>{
this.displayItem(imageItem)
});
}).catch(function(error) {
console.warn("error "+error);
});
}
async displayItem(imageItem){
var arr = [];
imageItem.getDownloadURL().
then((url) => {
console.warn("ur "+url)
arr.push(url);
this.setState({
isLoad: false,
urlImage: arr
})
}).catch((error) =>{
console.warn("error "+error);
});
// return await Promise.all(arr);
}
Please help. Thank you