Reputation: 1
I hope that somebody can help me with my problem.
I started learning React and I want to display images dynamically from an object named "project".
I am looping inside "projects" and pass each item as props of a component "Project".
It displays the other items (name, description, alt) but I can't get the images.
I tried this method : <img src={require(`./img/${project.image}`)}
but it doesn't work.
There is no error message, but it shows nothing.
I saw a lot of people have the same problem, but I tried everything...I don't know what to do.
This is my object:
The organization of my folder:
My component Project:
And the website:
Upvotes: 0
Views: 344
Reputation: 1
Thank you guys ! I found a way to do it.
I first imported the images to my object file "projects".
Then I imported my object and I made a loop
Finally, my component Project component Project
Thank you all for your help!
Upvotes: 0
Reputation: 395
You don't need to use require. It will work if you use it that way.
<img src={`./img/${project.image}`} alt={project.alt} />
I hope that will be useful.
Upvotes: 1