I'm trying to complete this countdown timer using a class component in REACT. I believe I'm just missing "this.Setstate" adding . Can you please review and let me know where that would be added in this component? Thanks in advance! (I've edited the code by adding "this.Setstate", however, I'm receiving an error message that it's not a function). Just to add more detail, I'm trying to have the countdown timer start when the screen loads. It's not triggered by a button or anything.
import React,{Component} from "react";
class Countdown extends Component{
constructor(props){
super(props);
this.state={
days:30,
hours:720,
minutes:59,
seconds:59
}
}
componentDidMount(){
let countDownDate = new Date("Jul 30, 2022 11:00:00").getTime();
/*Function myFunc runs every second*/
let myfunc = setInterval(function() {
let now = new Date().getTime();
let timeleft = countDownDate - now;
this.setState({
days: Math.floor(timeleft / (1000 * 60 * 60 * 24)),
hours : Math.floor((timeleft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
minutes: Math.floor((timeleft % (1000 * 60 * 60)) / (1000 * 60)),
seconds: Math.floor((timeleft % (1000 * 60)) / 1000),
})
} , 1000);
}
render(){
return (
<>
<div>
<p>{this.days}</p>
<p>{this.hours}</p>
<p>{this.minutes}</p>
<p>{this.seconds}</p>
</div>
</>
)
}
}
export default Countdown;