Home > OS >  Load local image in React JS
Load local image in React JS

Time:02-05

im unable to Load local image in React JS this is the file location:

ive tried using

<img id="shoe1" src="shoe1.jpg"alt="shoe1"/>
<img id="shoe1" src="./shoe1.jpg"alt="shoe1"/>

enter image description here

and within the folder like this too:

<img id="shoe1" src="../img/shoe1.jpg"alt="shoe1"/>
<img id="shoe1" src="./img/shoe1.jpg"alt="shoe1"/>

enter image description here

CodePudding user response:

Are you importing the image on top of the files you want to use them? You should follow this page from the documentation:

https://create-react-app.dev/docs/adding-images-fonts-and-files/

import shoe1 from './shoe1.jpg';

CodePudding user response:

import imgg from "../img/shoe1.jpg";

<img src={imgg} alt="yourimagecomeshere" />

CodePudding user response:

If your image placed in the same folder(the first picture):

<img id="shoe1" src="shoe1.jpg" alt="shoe1" />

If your image placed in the img folder(the second picture):

<img id="shoe1" src="img/shoe1.jpg" alt="shoe1" />

CodePudding user response:

can you move the image to assets folder and do something like this

<img id="shoe1" src="../assets/shoe1.jpg"alt="shoe1"/>
  •  Tags:  
  • Related