News for hackers. Stuff that matters.
Re:Making SetInterval Declarative with React Hooks by jakelazaroff on Monday February 04, 2019 @12:31AM (#19074192)
The difference is that closedVariable would be created inside intervalFn (the component). In addition, the intervalFn may run many times, but the interval will only be set up once. This example illustrates the problem: https://jsfiddle.net/ov2msa4e/

Your code avoids the closure problem, but closedVariable would be more like a static variable — it'd be shared by every instance of the hook. Probably not what you intended!

Re:Making SetInterval Declarative with React Hooks by Stoids on Monday February 04, 2019 @12:48AM (#19074247)
Thank you for the example, Jake! It was very helpful. You and Jason's answer cleared it up for me.