I'm trying to retrieve my images from a folder inside my firebase storage, I've tried to store the URL in an array and then attempted to map through and use the URLs to render them in a component but I'm unable to do so. I've tried multiple attempts but can't figure out why, I believe it's a promise that hasn't been resolved but again, unable to work it out. id like this to load when the ViewPhotos component has loaded. am I going about this in the completely wrong direction?
const ViewPhotos = () => {
const [imgData, setImgData] = useState([])
let getData = () => {
const storage = app.storage()
const storageRef = storage.ref('test/')
const newImg = storageRef.list()
newImg.then((res) => {
res.items.map((item)=> {
let url = item.getDownloadURL()
setImgData([...imgData, url])
})
})
}
const ListDisplay = ({ url }) => {
return (
<div>
<img src={url}/>
</div>
)
}
useEffect(() => {
getData()
},[])
return(
<div id="viewPhotos">
<h3>view photos component</h3>
<div>
{imgData.map(url => {
return <ListDisplay url={url} />
})}
</div>
</div>
)
}