I can`t load multiple image in react.js

Viewed 72

I had my Images in src/postimages/(5 images) for each post one image,

const [post, setPost] = useState({
        id:"",
        blogImage:"",
        blogText:""
    });
                      
 <img src = {require('../../postimages/' + post.blogImage)} alt="Images" />

The Error is the following:

Module not found: Can't resolve '../../postimages'

for one image I can access by importing the one image:

import blogImage from '../../postimages/img1.png';

How can I get 5 images respective with the different id`s?

1 Answers

Assuming the single image name is, for example, img1 (post.blogImage = 'img1')

<img src={`{../../postimages/${post.blogImage}.png}`} alt="Images" />
Related