i want my state to update every 1sec but its not working.
when I console logged this second, it works OK, but the screen is not updated
below is my codes
import React, { PureComponent } from 'react';
const date = new Date()
let seconds=date.getSeconds()
class Timer extends PureComponent {
state={
seconds:seconds,
}
changeSecond=()=>{
this.setState((prevState)=>{
this.state.seconds=prevState.seconds+1
})
}
componentDidMount(){
this.interval=setInterval(this.changeSecond,1000)
}
componentWillUnmount(){
clearInterval(this.interval)
}
render() {
return (
<>
<div>{this.state.seconds}초</div>
</>
)
}
};