Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!