Hello, I am making a component that shows the current date, but I would like it to update as soon as the change occurred, but I was only able to leave it active for a change with a timeout, which I think is not a good solution, all the time unnecessarily or I would have to adjust a high value which could cause a delay at the time of the update.
this.state = {
curDate : null
}
componentDidMount() {
setInterval( () => {
this.setState({
curDate : new Date().getSeconds()
})
},1000)
}
render() {
return (
<div>
<p>{this.state.curDate}</p>
</div>
);
}