0

I am trying to access an image that is in the public folder inside a js file that is in the src folder? To be more specific, I am styling a div container. I want to set its backgroundImage property to the image file in the public folder. How would I do do that? Thank you for your responses!

  • Does this answer your question? [ReactJS and images in public folder](https://stackoverflow.com/questions/47196800/reactjs-and-images-in-public-folder) – Drew Reese May 19 '20 at 07:06

2 Answers2

1

You don't need any kind of configuration for this purpose. Simply use the regular html tag

 <img src= "yourimage.jpg" /> 
Bibek
  • 943
  • 1
  • 12
  • 22
  • I'm trying to set the background-image property of a div container to an image in public folder. How would I write that in code, specifically in a .js file? Thank you for your help by the way. – Konstantin Victoria May 19 '20 at 07:24
0

You can use an inline style prop and define the background rules.

<div style={{
  backgroundImage: "url(pathToFile)",
  // other various style rules to size and position
}} />

Edit use local image for background

Drew Reese
  • 165,259
  • 14
  • 153
  • 181