When we have a tick
function
tick() {
this.setState({
date: new Date()
});
}
why should we use something like,
componentDidMount() {
this.timerID = setInterval(() => this.tick(), 1000);
}
and not just simply
componentDidMount() {
this.timerID = setInterval(this.tick, 1000);
}
I guess that we have some closure problem when I try the second variant. But can you please explain in detail what happens.
You can find the rest of the code here.