Loading images based on JSON file react

2372 views reactjs

I have a create react app. I am making an AJAX request and I receive JSON that looks like this.

{id: "b2", title: "Huang's World", episodes: 12, product_image_url: "/images/huangsworld.jpg"}

In my create react app I have an images folder that has all of the corresponding images, I want to load the image based on the product_url.

<img src={ product_image_url} <--- Doesn't work

any suggestions?

answered question

You need quotes around it: <img src={"/images/huangsworld.jpg"}

Sorry, I meant the variable product_image_url doesn't work, because the path is incorrect. Is it a problem with webpack

1 Answer


Try changing your product_image_url to bg in the JSON.

posted this

Have an answer?


Please login first before posting an answer.