Here is what I am trying to do:
imageArray = ["../images/a.png", "../images/b.png"];
function renderImages(number){
const imageElements = [];
for(let i = 0; i < number; i++){
const imageSrc = imageArray[i];
imageElements.push(<img src={ require(imageSrc) } alt=""/>);
}
return imageElements;
}
The code works fine, the problem is the image source, I can put a static image source and it will work (I tried that), but when the source is dynamic (data coming form an array which is coming form a json file) does not work. Is there any solution to this?
Thanks in advance!
Edit:
The error I get is: Error: Cannot find module ".".
This could be a webpack problem
SOLUTION
For people who have the same problem, I was able to solve this problem by following this link: Dynamically import images from a directory using webpack