0

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
1
  • try wrapping your src using { }. like this <img src={"image path"} /> Commented Jan 6, 2023 at 8:31

1 Answer 1

4

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

<img src="/your-image-name.png" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.