Home > front end >  referencing an image in public folder react js
referencing an image in public folder react js

Time:02-03

This is driving me slightly mad. I've searched all around and think I am doing everything right...But clearly am not!

All I'm trying to do is set a bg image from a picture in my public folder, but it keeps throwing an error!

(see below, code with folder tree and error message)

Even the greyed out code on line 10 does not work.

Any help would be much appreciated.

Many thanks from the #noobcoder, ClaaziX

relating code

error message

CodePudding user response:

By defaul your public folder is accessible anywhere in your code just reference it like this below, change your image src to something like this

<img src='/images/Lightning.jpg'/>

CodePudding user response:

The error message comes from RainDrops.module.css, but to answer your actual question regarding images in public folder, you can reference them without using the environment variable. This was also answered in this question.

Your code should look like this:

<img alt="Lightning" src="/images/Lightning.jpg" />
  •  Tags:  
  • Related