Accepted answer

With your setImages({ images: imageArray }) call, you'll get value of images const to be:

images = {images: [...]} // [...] is the imageArray

so you'll have to access it as images.images, or rather set it as setImages(imageArray) which will be accessible as you expect.

Also, access the state variable and use map instead of forEach, not the imageArray. So instead of imageArray.forEach(...) use Map returns an array with values returned from the function calls. Whereas forEach returns undefined.


{imageArray.length>0 ? 
    <img src={element} alt="" />

Hope this solves

Related Query

More Query from same tag