Skip to content
Advertisement

how to map through multiple images, after connecting to a third party api

I’ve managed to connect to an api, which returns images of dogs. However, I’m stuck on how to map more than one image, without repeating code. I essentially want to display a grid with(lets say 9) images, all with different dog images from this api.

At the moment, it displays one image with a json object mapped out underneath it.

App.js

JavaScript

FetchAPI.js

JavaScript

Advertisement

Answer

If your API returns single image at a time and you want more images on button click then you should have to append the new image into the array like:

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