0

I have to issue in displaying the image in react. List of all Image urls in get from firebase storage.Passing all the urls display the image shows urls.map is not a function

const ViewImages = () => {

var storageRef = firebase.storage().ref("images/");

const [image, setImage] = useState(""); const [urls, setFiles] = useState("");

const [imageUrl, setImageUrl] = useState([]);

useEffect(() => { const fetchImages = async () => {

let result = await storageRef.child('images1/').listAll();
    let urlPromises = result.items.map(imageRef => imageRef.getDownloadURL());
 
    return Promise.all(urlPromises);
    //console.log(urlPromises);

}

const loadImages = async () => {
    const urls = await fetchImages();
    setFiles(urls);
    console.log(urls[0]);
}
loadImages();
}, []);

return(

      {urls.map((urls,i) => (
          <img src={urls} key={i}/>
      ))} 
     
  </div>

);

}

export default ViewImages;

1 Answer 1

2

The issue is you're calling the map method on an empty string ('') which is the initial value of urls. Set it to an empty array instead.

const [urls, setFiles] = useState([])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.