I'm learning React, following their tutorial. They made a clock component which updates itself, and has these functions:
tick () {
this.setState({
date: new Date()
});
}
componentDidMount() {
this.timer = setInterval(
() => this.tick(),
1000
);
}
They called setInterval
with an anonymous (arrow) function, that only calls tick
.
My Question:
Why does the above work, while placing this.tick
like I did below doesn't?
componentDidMount() {
this.timer = setInterval(
this.tick,
1000
);
}