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

133
Vistas
Convert string to import call in React

I have the following imports in my project:

import video1 from '../../assets/video1.mp4';
import video2 from '../../assets/video2.mp4';

and the following code:

...
constructor(props){
    super(props)
    this.state={
        videoURL: this.props.source,
    }
}
render(){
return(
<div className='app'>
    <video onTimeUpdate={(e) => this.videoBuffer(e)} id="videoPlayer" ref="VidRef" src={this.state.videoURL} muted={this.state.muteVideo} onClick={(e) => this.togglePlayPause(e)} autoPlay></video>
</div>
)}

after i get back the props from another component, they appear as string, ie, "video1" and "video2" which are then passed to src of the video component. Unfortunately i am not able to render the video component as

src="video1"

is not valid. Is there a way to convert "video1" to the import that i have made above in line 1? since i have thousands of videos, i cannot use arrays.

i also do not want to use dangerouslysetinnerhtml to avoid any openings to xss attacks.

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