Shubham Singh
Shubham Singh

Reputation: 23

Why the image does not get rendered by directly using src attribute in react?

In my react project when I used src="" to provide address for an img element it didn't get rendered while I use the same image address with import it worked well.

This is when I used src attribute This is when I used src attribute

This is when I used import enter image description here

Why is this happens?

My working directory:

/public
    index.html
/src
App.js
index.js
    /components
        Contact.js
    /images
        felix.png

Upvotes: 0

Views: 35

Answers (1)

Manish Jha
Manish Jha

Reputation: 345

You need to add image to public directory so you can directly access it through src like :

<img src="/your-image-name.png" />

Upvotes: 4

Related Questions