News for hackers. Stuff that matters.
Re:Making SetInterval Declarative with React Hooks by jasonkillian on Monday February 04, 2019 @12:39AM (#19074220)
The difference is subtle (and took me a bit to figure out!). In the article's example component, the component's "main" function gets re-run on every render and a new `count` variable is created each time. The effect function is only run once at the very first render, and only captures the value from this first render.

I'm having a little trouble explaining the difference well, I think this jsfiddle illustrates the incorrect case the article is talking about representatively: https://jsfiddle.net/7fLnvz5c/

Re:Making SetInterval Declarative with React Hooks by Stoids on Monday February 04, 2019 @12:50AM (#19074255)
Thanks Jason, this was very helpful for me. I think I was having trouble making the mental jump from reading the code as a normal function with state vs how a component instance is called and handled by React at runtime--your example helped me make that hurdle.