Skip to content
Advertisement

Error: animal.image.map is not a function

I am currently making a shelter web app using mern stack and i am struggling to display an image from my object. i already used the map but i think it is only for array objects. so i am clueless how to get the images.url on my animal object.

this is my animalSchema

JavaScript

AnimalReducer

JavaScript

and this is what i use on my frontend for showing the animal details

JavaScript

Animal’s name, gender, breed and type are showing, only the animal.url is not.

Advertisement

Answer

It looks like your schema has animal.image defined as an object. Array.prototype.map only exists on arrays, not objects.

JavaScript

So you can remove the map and instead conditionally render the div:

JavaScript
Advertisement