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

261
Vistas
React Native setInterval running 5 or 6 times after clearInterval has been ran

I am currently developing an app in React Native that includes a stopwatch that is stopped when the phones Gyroscope picks up a certain amount of movement. To do this I am using a setInterval to check for updates on the Gyroscope and if requirements are met, stop the timer. However, the issue arises when the setInterval is running usually 5-6 times after being stopped by both clearInterval and using a hook to check if the game has started. Currently the setInterval is set to 1 ms but it still has the same issue no matter the interval whether it be 1000ms or 10000ms.

const stopwatchINT = setInterval(() => {
 if (gameStarted) {
  if (data.x > 0.2) {
    clearInterval(stopwatchINT)
    let endTimer = performance.now()
    setTimeTook(Math.round(endTimer - startTimer) + 'ms')
    playSound()
    setContainer(WHITE)
    setGameStarted(false)
    setReactionScreenDisplay({'select': 'none','singleCreate': 'none', 'reactionGame': 'none', 'flash': 'none', 'timeTook': 'block'})
  }
 }
}, 1)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Never mind I have solved the issue. For anyone who gets stuck on this you can enclose the setInterval in a useEffect which was what was throwing me as I forgot to pass the hooks in the array. For example:

  useEffect(() => {
  if (isStart) {
    const timer = setInterval(() => {
      if (count > 0) {
        setCount(count - 1)
      } else {
        setCount('Times up');
        clearInterval(timer);
      }
    }, 1000);
  }
}, [isStart]);
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