Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
Is there an alternative to using the import or require statement for images before they are created in react. Using jango, react, and webpack

I would like to dynamically render images to a webpage in react. I can do this if the images exist on the backend doing something like this:

render(){ return(....
<CondRenderImg
shouldRender={this.state.jobDone}
imgPath={require('./generatedData/imgs/LatvsLongprecluster.png')}
/>
);
}

where the condition render looks something like this

import React from "react";




class CondRenderImg extends React.Component{
    constructor(props){
        super(props);
    }

    render() {
        const doRender = this.props.shouldRender;
        if(doRender){
            return(

                <img src={this.props.imgPath} style={{ height: "450px", width: "100%" }} alt={"viz"}/>
            );
        }
        else {
            return (
                <div>
                </div>
            );
        }

    }

}export default CondRenderImg;

This much works. The problem is that I seem to need the require statement. When I compile this code [npm with webpack]'./generatedData/imgs/LatvsLongprecluster.png' may not exist YET. The image I create is dependent on user input and is created by a post request. If the request is good it sets the flag to true and shows the created image.

SO the QUESTION is how can I get around the require or import statements? My understanding is that it is bonded at compile time so is there truly a way to dynamically create and load images in react?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda