0

How can I show images from json file in localhost in React Application? I'm tryig this below one but it is not working.

json file:

{
  "img":"images/img-filename.png"
}

image is located at src/images/img-filename.png

In React app, image path is displaying: images/img-filename.png

Ali
  • 1
  • 2

1 Answers1

0

Images from src folder can be displayed in React component by:-

<img height="32" src="../images/img-filename.png" />

../ is to go one folder out. I hope it helps.

Avinash
  • 1,195
  • 9
  • 17
  • I did that, still not showing... file path is coming from .json file. Path is displaying as mentioned in .json but image is still not displaying – Ali May 14 '19 at 15:12
  • @Ali when you render img object, also add `../` in src – Avinash May 14 '19 at 15:33
  • json path: { "img" : "../images/img-filename.png" } React file: – Ali May 14 '19 at 15:53
  • It is showing images, after I moved the images folder to the public folder. – Ali May 14 '19 at 16:06