Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 139923

Getting this.startBreak() is not a function error in react.js

$
0
0

I'm a newbie working on a pomodoro timer app in react and I'm getting this error after calling a function within setInterval():

TypeError: this.startBreak is not a function

Surely it's something trivial so I'll be grateful for any advice. Here's the code:

startSession = () => {

let sessionSecondsTotal = (this.state.hours * 60 * 60) + (this.state.minutes * 60) + (this.state.seconds);
let hoursNode = document.getElementById("hours");
let minutesNode = document.getElementById("minutes");
let secondsNode = document.getElementById("seconds");



let hoursShow = this.state.hours;
let minutesShow = this.state.minutes;
let secondsShow = this.state.seconds;


setInterval(function(){                                         
      secondsShow = secondsShow - 1;
      if(secondsShow <= 0){
          secondsShow = 59;
          minutesShow = minutesShow - 1;
      }else if(hoursShow > 0){
        if(minutesShow <= 0){
          hoursShow = hoursShow - 1;
          minutesShow = 59;
        }
      }

      hoursNode.textContent = hoursShow.toString();
      minutesNode.textContent = minutesShow.toString();
      secondsNode.textContent = secondsShow.toString();

      sessionSecondsTotal = sessionSecondsTotal - 1;

      if(sessionSecondsTotal === 0){
        this.startBreak();
      }

  },1000)
}

Viewing all articles
Browse latest Browse all 139923

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>