Nandhini Kajol
Nandhini Kajol

Reputation: 95

Map a set of Images into a image tag in react component

I have 20 images in my src folder src/images i want to map that images into the image tag in a app.js. How to do this? Below is my Setup, I Get error by this.

import ImageDetails from "../data/ImageDetails";

{
    ImageDetails.map((Images) => {
        return (<img alt="doubt" src={ImageDetails.images} />)
    })
}

My Json:

[
  {
    "id": 1,
     "images": "../../assets/images/sample1.jpg",
  },
  {
    "id": 2,
     "images": "../../assets/images/sample2.jpg",
  },
  .
  .
  So on upto 20 images...
]

Upvotes: 0

Views: 668

Answers (1)

Monika Mangal
Monika Mangal

Reputation: 1760

import ImageDetails from "../data/ImageDetails";

{
    ImageDetails.map((Images) => {
        return (<img alt="doubt" src={Images.images} />)
    })
}

You need to use Images instead of ImageDetails inside the .map

Upvotes: 1

Related Questions