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

142
Views
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 answers
Answer question

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 Report
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!