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

134
Visualizações
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 à 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