I want to load img in ReactJS. But I can't put url img in require.
Note: const 'Photo' is url link of picture.
Any help will be appreciated..
Thanks.
This is the directory structure and 'photo' = "./upload/xxxxxxxxxx.jpg" enter image description here
You can require with expression.
So, this should work:
<img src={require('./upload/' + fileName)} />
The first part inside require is directory and the second one is fileName
e.g. my-image.png
.
Or there are various other ways to handle dynamic requires: map, switch
photo
is the url, then there is no need forrequire
, just use the constant directly.