HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptreactCritical

ReactJS and images in public folder

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
folderandreactjspublicimages

Problem

Im new in ReactJS and I want to import images in a component. These images are inside of the public folder and I do not know how to access the folder from the react component.

Any ideas ?

EDIT

I want to import an image inside Bottom.js or Header.js

The structure folder is:

I do not use webpack. Should I ?

Edit 2

I want to use webpack for loading the images and the rest of assets. So in my config folder I have the next files:

Where I need to add the paths of the images and how?

Thanks

Solution

To reference images in public there are two ways I know how to do it straight forward.
One is like above from Homam Bahrani.

using



And since this works you really don't need anything else but, this also works...

Code Snippets

<img src={process.env.PUBLIC_URL + '/yourPathHere.jpg'} />
<img src={window.location.origin + '/yourPathHere.jpg'} />

Context

Stack Overflow Q#47196800, score: 206

Revisions (0)

No revisions yet.