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

145
Visualizações
How to run a function every 30 seconds in React without having the DOM re-renders reset the countdown to 0

I need to have React running a function every number of seconds but the countdown shouldn't be restarted on a re-render of the DOM. So basically I want to run this function when the app starts, and every 30 seconds re-run the same function, but if when the DOM re-render I do not want to have the countdown to 30 seconds restart from 0. I was checking this answer How to call a function every minute in a React component? but each time the DOM renders the countdown is reset to 0. Is there a way to achieve this only using React?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Dennis. If we could see your code, it'd be easier to provide you with some kind of answer. However, with what I got, I imagine I can help you in a way. You see, if you want a function to be run every 30s, you can use the setInterval function for that. And you could store your current timer on your component's state. By doing that, every 1 second, your setInterval function would update the component's state, re-rendering the component but not reseting the timer, since the timer would retrieve its information directly from the state.

That being said, it would be awesome if we could see the code for what you're trying to do. With the code we can understand if you're working with state, Redux, hooks or anything else.

Hope I could help you clear something out!

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