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

117
Views
React Countdown Clock not sure if issue is with my setInterval or my setState

I've been working on FreeCodeCamp Front End development project 25 + 5 Clock. I'm trying to click the play button and make it countdown. I know it enters my countdown function but when logging it, I think it is only calling once. So I think my setInterval might be wrong but I've also struggled with using setState on all projects. They have only taught using this.setState and this has often caused problems because the state is not what I expect it to be (like it's not immediate). I'm not ready to dive into the concepts of DidMount, WillMount, etc so I'd like to stay in the boundaries of using setState if that is where my problem is. Below is a link to my codepen

25 + 5 Clock Codepen

handleCountDown(pause){
let timer;
if(pause){
  clearInterveral(timer)
} else {
  if(this.state.minutesLeft === '' && this.state.secondsLeft === ''){
    if(this.state.session){
        timer =  setInterval(this.countdown(Number(this.state.sessionLength), 0), 1000)
    } else {
      timer =  setInterval(this.countdown(Number(this.state.breakLength), 0), 1000)
    }
  } else {
    timer =  setInterval(this.countdown(Number(this.state.minutesLeft), Number(this.state.secondsLeft)), 1000)
  }   
}}

countdown(min, sec){
const second = 1000;
const minutes = second * 60;

const countDate = (new Date().getTime()) + (second * sec) + (minutes * min);//target time
const now = new Date().getTime();
const gap = countDate - now;



const textMinute = Math.floor(gap / minutes);
const textSecond = Math.floor((gap % minutes)/ second);

if(textSecond === 0){
  textSecond = '00'
}
this.setState({
  minutesLeft:textMinute.toString(),
  secondsLeft:textSecond.toString()
})}
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!