Image does not render

Asked

Viewed 62 times

0

I’m taking any image in a folder at the root of the project and the image doesn’t render... There’s that image icon with the alt. I’ve looked at several topics and sites, I do everything exactly the same and the image doesn’t render. However, when I use the import javascript, it renders normally. I’m using Reactjs.

have tried:

<img src={require('../../images/planetsCard/Hoth.png')} alt="planet"/>

<img src={'../../images/planetsCard/Hoth.png'} alt="planet"/>

What I’m doing wrong???

  • With require should work... How is the image generated HTML?

  • Have you ever tried to do require('...').default?

  • I tried to require('...').default and it didn’t work :/

  • html is retouching like this : <img alt="Tatooine" src="[object Module]">

1 answer

1


Hello, try to import like this:

import planetsCard from '../../images/planetsCard/Hoth.png';

<img src={planetsCard}/>
  • as I said, this way it works normally, but it is not the option I can use at the moment because the image request is inside a map

Browser other questions tagged

You are not signed in. Login or sign up in order to post.