'How can I import image file with react?
Solution 1:[1]
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" />
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | lissettdm |
Solution 2 | Stefan Georgiev |