Reputation: 503
I am trying to fetch images from Firebase storage and then display them in my react app. Currently, there are 4 images in my storage and want to display all.
Fetch 4 different images from storage properly but displayed first image(1.png) 4 times.
useEffect(() => {
const fetchImages = async () => {
let result = await storageRef.child('images').listAll();
let urlPromises = result.items.map(imageRef => imageRef.getDownloadURL());
return Promise.all(urlPromises);
}
const loadImages = async () => {
const urls = await fetchImages();
setFiles(urls);
}
loadImages();
}, []);
am I using map wrong?
<div>
{files.map((index) => (
<img key={index} src={files} />
))}
</div>
Upvotes: 0
Views: 91
Reputation: 8751
You should set each array element.
<div>
{files.map((file, index) => (
<img key={'unique_key_string' + index} src={file} />
))}
</div>
Upvotes: 3