Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

362
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda