Oğuzhan
Oğuzhan

Reputation: 81

How can I import image file with react?

I have a images files but react is not take them ı cant import like that. Otherwise when i try

<img src={require("/FileAdress")} className="Logo" alt="logo" /> Nothings came and not recognized

whats the problem anyone help ? enter image description here

I have a logo folder inside image logo.png but ı cant see now

Upvotes: 1

Views: 662

Answers (2)

Stefan Georgiev
Stefan Georgiev

Reputation: 39

IF you are planning to deploy your react app later on with Netlify I would suggest you store your images in the public folder. That way then they can be easily accessed during development but they would also not cause any errors later on when deployment.

Example code:

<img
className='deleteBtn'
**src='/images/delete__btn.png'**
alt='Delete a product if admin'
/>

Example snapshot

Upvotes: 0

lissettdm
lissettdm

Reputation: 13078

If you are using create-react-app you can add an image this way:

import Logo from 'path/to/logo.png';

<img src={Logo} className="Logo" alt="logo" />

Upvotes: 0

Related Questions