Thanks for your comment and I completely agree with you here 😍.
As Dan Abramov says in his article that each render has its own event handler. I know this is applicable when your event handler consumes some state or props variable so that you don't end up storing the stale value (closures).
But here for the sake of ingesting this new knowledge of using hooks, I was setting up an initial mindset for my readers and direct their attention towards using the side effect inside useEffect hook. I didn't want to set opinion or emphasize on some best patterns. That could be a completely separate article 😀
Hi Lougie,
Thanks for your comment and I completely agree with you here 😍.
As Dan Abramov says in his article that each render has its own event handler. I know this is applicable when your event handler consumes some state or props variable so that you don't end up storing the stale value (closures).
But here for the sake of ingesting this new knowledge of using hooks, I was setting up an initial mindset for my readers and direct their attention towards using the side effect inside useEffect hook. I didn't want to set opinion or emphasize on some best patterns. That could be a completely separate article 😀
Thanks again for reading this article. 👏
Moving the
handler
function insideuseEffect
would fix this nicely (and in fact I see you already did this in the demo).