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

92
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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