Skip to content
Advertisement

How to render all image srcs on react

I have a product object and inside that object has an answer object and inside that has a photo property where some answers have photos. I tried creating a method that loops through every images array and creates and img tag and includes that src link but for some reason its not showing any image. I even console logged it and the links were appearing. Is there some simple way to do this that I’m missing?

JavaScript

Advertisement

Answer

Map and return the mapped array instead of using forEach.

Also, it would be preferable to use JSX syntax (equivalent to React.createElement) instead of invoking a function that returns a component. (Invoking a standard function that returns JSX can cause problems with hooks, among other things)

JavaScript

or

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement