4 ms·
They also eliminate subtle bugs that can emerge from `this` being mutable in classes, and they make the React lifecycle more intuitive. Rather than thinking abo
by city41 5y ago
They also eliminate subtle bugs that can emerge from `this` being mutable in classes, and they make the React lifecycle more intuitive. Rather than thinking about whether the component did mount, will mount or will unmount, you just associate side effects with certain states.
Dan Abramov has a nice write up on the pitfalls of mutable this: https://overreacted.io/how-are-function-components-different-from-classes/ https://overreacted.io/how-are-function-components-different...
With all that said, I would still say I'm not really a fan of hooks. I more see them as a necessary evil than a great feature. I try to use them as minimally as possible.
- brundolf 5y agoWorth noting that mutable-this can be made to work by using something like MobX. It’s not a fundamental problem, just one that React declined to solve directly, which I can’t totally blame them for.