blog/hooks-dependencies-and-stale-closures #80
Replies: 6 comments 6 replies
-
I'm a very law-abiding developer in React world. I pretty much always follow the React eslint rules and hints. But it gets me staggered for a couple of seconds when including a callback in, say, a I do eventually give in and do the thing. It just makes me wonder if I go about it the wrong way, as it feels like a premature optimization at times (maybe it's just all those "you don't need constant |
Beta Was this translation helpful? Give feedback.
-
Very nice explanation. The cause of many hard to locate bugs! |
Beta Was this translation helpful? Give feedback.
-
I still don't understand how do I use |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hi, I think when you say snap a picture, it can be confusing, technically it captures the reference of that variable, not just the value
For react, when the component re-render, the variable reference changes, that's why it close on the last value for the memoized function |
Beta Was this translation helpful? Give feedback.
-
blog/hooks-dependencies-and-stale-closures
Let's demystify what stale closures are in combination with react hooks with the help of the analogy of taking a photo ...
https://tkdodo.eu/blog/hooks-dependencies-and-stale-closures
Beta Was this translation helpful? Give feedback.
All reactions