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

93
Views
How to get ReactJS video src to conditionally change

I am trying to conditionally change the background video src based on what my current state value is inside my functional component however it will not change the video. If my {weather.weather} state is 'clouds' I want the video src="./sand.mp4" else, I want src="./beach.mp4".

The videos are loading correctly with the conditional on the initial render but won't update according to state value. The state changes correctly on my button click and will console.log correctly to the value. I am not managing the video src with state and am just using the path to the file. I tried managing the video src with state and I was having the same issue where the video will not change. I'm thinking it may need a re-render but am unsure how to go about this.

**All other code and state change is handled through an input & submit button

<video autoPlay muted loop id="background-video">
  <source src={weather.weather === "clouds" ? "./sand.mp4" : "./beach.mp4" } type="video/mp4" />
</video>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Working example at codesandbox

To understand this in detail visit this question. This one is a duplicate.

about 4 years ago · Juan Pablo Isaza Report
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!