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

84
Vistas
Create a react state that changes with time

I am creating a game with react and i want to add a chronometre feature to track time but i tried to use settimeout and it failed bcs every render the settimeout recall and i tried setinterval but failed also can anyone suggest me a way to to this the game is a tenzies game

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you are using a functional component then you are going to have to set an interval constant in the useEffect() hook:

useEffect(() => {
  const interval = setInterval(() => {
    //code inside here will run every second
  }, 1000); //change the 1000 to however many miliseconds you want between execution
  return () => clearInterval(interval);
}, []);

This code will run whatever is in the setInterval body every second, but this amount can be changed (change the '1000'). The interval will then be cleared. Note that this interval will stop counting when the component is unmounted

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