I'm trying to learn React and I don't understand why this does not do anything when I try without an arrow function
componentDidMount() {
var self = this
this.timer = window.setInterval(function () {
self.increment
}, 1000)
}
Is the correct pattern self.increment()
?
So why do I need the () when I don't need it in:
componentDidMount() {
this.timer = window.setInterval(this.increment.bind(this),1000)
}