Twitter | Search | |
Adam Rackis Feb 21
Even experienced React devs need to be careful applying old mental models to hooks, in particular instance-bound methods. Consider this code—line 32 If props.onClick never changes, this is fine, right? In fact it might work fine! 🎉 Or it might fail in the baffling ways 🙈 1/
Reply Retweet Like
tom tom dot com Feb 21
Replying to @AdamRackis
So *if* props.onClick never changes, it *is* fine... the tricky thing is being sure that it won't change
Reply Retweet Like
Adam Rackis Feb 21
Replying to @pelotom
It turns asking whether props.onClick changes is a harder problem than you might think. We took a lot for granted, being used to class-based components, with mutable `this`.
Reply Retweet Like
tom tom dot com Feb 21
Replying to @AdamRackis
Yep, it's best to assume it's changing more often than you think
Reply Retweet Like
Fredrik Höglund
The best mental rule I’ve found so far with hooks is ”code as if any value can change at any time”. No downsides really and keeps you safe from a lot of the bugs that are hard to wrap your head around. :)
Reply Retweet Like More