I'm currently trying to do the React tutorial at https://en.reactjs.org/docs/state-and-lifecycle.html. In the code there is the following block with an arrow function.
https://codepen.io/gaearon/pen/zKRqNB?editors=0010
componentDidMount() {
this.timerID = setInterval(
() => this.tick(),
1000
);
}
As a beginner, I have little experience with Arrow functions and don't quite understand when it makes sense to use them, so I would like to write it as a normal function. So I changed my code as follows:
componentDidMount() {
this.timerID = setInterval (
function() {
this.tick();
},
1000
);
}
However, then the code no longer works. Can someone help me please? Where is the mistake?