Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
How to display image from src/images without using import at the top and without using public directory in react/reactjs

I want to render the star1.png located in src/images/ directory without using import at the top and without using the public directory.

My code:

import React from "react"
import ReactDOM from "react-dom"

class App extends React.Component
{
    render(){
        let starIcon = "./images/star1.png"

        return(
            <>
                <h1>Hello</h1>
                <img src={starIcon} />
            </>
        )
    }
}

ReactDOM.render(<App />, document.getElementById("root"))
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

I'm not sure if I understand your question fully, but you could pass the image as a blob through props and set that blob as the source of the image.

about 4 years ago · Juan Pablo Isaza Relatório

0

The problem is related to the prod build I think because when you created a build asset directory will not copy.

Solutions:

  1. You can import it'll be added to the bundle it'll work
  2. You can move to the public it'll also be added in the build/dist directory
  3. You can manually/automatically copy assets to the build/dist directory.

The last solution you are looking I think.

about 4 years ago · Juan Pablo Isaza Relatório

0

I found the answer to my question which is using require:

let starIcon = require("./images/star1.png")
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda