i want to set countdown timer start at 00:00 and repeated every 5 minute.(example: when time is 00:05 timer is countdown 5 minutes until 00:10, and in 00:10 countdown 5 minute again, and so on)
this is my code now :
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
minutes: 5,
seconds: 0
};
}
...............
componentDidMount() {
this.getData();
this.myInterval = setInterval(() => {
const { seconds, minutes } = this.state
if (seconds > 0) {
this.setState(({ seconds }) => ({
seconds: seconds - 1
}))
}
if (seconds === 0) {
if (minutes === 0) {
clearInterval(this.myInterval)
} else {
this.setState(({ minutes }) => ({
minutes: minutes - 1,
seconds: 59
}))
}
}
}, 1000)
}
...........
return (
<p>Countdown : {this.state.minutes}:{this.state.seconds < 10 ? `0${this.state.seconds}` : this.state.seconds} </p>
);
}
}
where i should change or add to make this countdown start at 00:00 and repeated every 5 minute. anyone can help me?
setIntervalcallback that counts down every second (1000ms) for 300 seconds and resets itself? I'm not quite understanding the at 00:05 countdown to 00:10, how does one count down from 5 to 10?