I'm new to react, I'm trying to display images from the src/images folder. but after inserting the correct path, then also the image is not visible. Here you can see my img tag path and on the left side folder structure
Asked
Active
Viewed 252 times
1 Answers
1
From the Image you provided, looks like you used require("path...")
which is not a good way to do so, its valid tho, but not a good practice, its recommended and is common to use import X from "somewhere"
syntax.
I suggest you to use either of these two ways to use images in react.
- put images in
public
folder and use relative links in thehref
tag, i.e:
<img href="/images/panda.png" alt="cute panda" />
- put images inside a folder somewhere inside
src
folder like you did in the image and import images using ES import syntax, and use imported image variable in{}
expression forsrc
prop, i.e:
import PandaImg from "../images/panda.png"
const Panda = ()=>{
return <img src={PandaImg} alt="cute panda" />
}
Here is a CodeSandbox Example may help you further explore the code in broader context.

Akam
- 131
- 6