0

I'm trying to use an image of a search icon on my site, but it's not loading. I keep making sure my directory to the image is correct and it all looks good to me. I am currently in my Navbar>Index.js file and trying to get to my folder assets/icons/search.png

                    <img src={require('../../assets/icons/search.png')} alt="Search" />

my directory

image not loading on my site

isaac2324
  • 53
  • 1
  • 8
  • I think this is similar to https://stackoverflow.com/questions/39999367/how-do-i-reference-a-local-image-in-react Are you using webpack? Only then you need to use require, otherwise you can directly provide the path – Lakshya Nov 06 '20 at 06:10

1 Answers1

1

In React you have to first import the image before you can use it.

import Image from '../../assets/icons/search.png'

Then you can use it like this

<img src={Image} alt="Search" />
Kyle Lambert
  • 369
  • 2
  • 13