4 ms·
The difference is that closedVariable would be created inside intervalFn (the component). In addition, the intervalFn may run many times, but the interval will
by jakelazaroff 8y ago
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/ 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!
- Stoids 8y agoThank you for the example, Jake! It was very helpful. You and Jason's answer cleared it up for me.