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

363
Visualizações
How would you approach thiscontrolling this 2 traffic lights system in React.js

I am trying to create a simple crossroad with 2 traffic lights that are dependent on each other (just like in real life). The traffic light will turn green/red based on the traffic data we receive from the backend. There is a totalAmountTime variable which holds the total amount of one cycle. Let's take totalAmountTime =10

The default data of the first cycle is [6,4] (6 seconds green for the bottom to up direction and then 4 seconds green for the right to left direction)

Every 10 seconds(totalAmountTime ) we have to fetch an endpoint taking the traffic data and then render dynamically the time for each direction. Lets suppose the data from backend is an array like [2,8] , the first one holding green seconds from bottomToUp direction

Here you can see the code on stackblitz and the way I approached it but it's not working. I think I'm not using right the useIntervals and setTimeouts

https://stackblitz.com/edit/react-mq4teg?file=src%2FApp.js

enter image description here

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