Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!