January 2020
Intermediate to advanced
530 pages
11h 11m
English
The tick() method, as shown in the following, sets a timer that runs for 15 minutes:
tick(){ var min = Math.floor(this.secondsRemaining / 60);var sec = this.secondsRemaining - (min * 60);this.setState({ minutes: min, seconds: sec})if (sec < 10) { this.setState({ seconds: "0" + this.state.seconds, })}if (min < 10) {this.setState({ minutes: "0" + this.state.minutes, })}if (min === 0 & sec === 0) {clearInterval(this.intervalHandle);clearInterval(this.intervalBalance); } this.secondsRemaining--;}
Every interval, the tick() method sets the minutes and seconds state variable. It also fixes the formatting as per the 00:00 format when the seconds or minutes are single digits. When both minutes and seconds are equal to zero, it clears the timer ...
Read now
Unlock full access