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

129
Visualizações
Loosing the time in SetInterval in react

I have setInterval function where a timer will be running.

Issue:

For example if we have 2 menus, one is home and 2nd is timer(where our timer is running), if I stay in timer page, SetInterval timer is working fine, but if I visit home page, the timer is starting where I left the page.

Requirement:

Even if I visit the Home page, the timer should not stop, it should go continuesly.

Code:

    const pad = (val) => {
        return val > 9 ? val : '0' + val;
   };
   startTimer = () => {
       let timer = setInterval(function() {
            document.getElementById(`seconds-${accountId}`)
                ? (document.getElementById(`seconds-${accountId}`).innerHTML = pad(++sec % 60))
                : null;
            document.getElementById(`minutes-${accountId}`)
                ? (document.getElementById(`minutes-${accountId}`).innerHTML = pad(parseInt(sec / 60, 10)))
                : null;             
        }, 1000);
    }

 componentDidUpdate(){
     this.startTimer();
  }
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