While studying React, I came across following code block here:
this.timerID = setInterval(
() => this.tick(),
1000
);
Here, the first argument to setInterval is a function that returns tick() function. If I replace the 1st argument to setInterval with just this.tick
, it does not work (meaning, clock stops ticking). Whereas it works with just passing the function here.
Why is it so?
setInterval takes in a function. Why do we have to pass in an arrow-function that returns a function instead?