r/reactjs • u/callensm • Oct 31 '18
Why the hate for React Hooks?
I've been seeing a lot of mixed feelings about React Hooks since it was announced and can't quite figure out why. Sure it's a deviation from the norm, but completely optional and certainly lowers the barrier to entry for new developers.
Can someone explain why all the negative feelings are rising about it?
19
Upvotes
View all comments
Show parent comment
1
u/smthamazing Apr 26 '19
First of all, there is no inherent problem with the style itself. Any high-performance functional language (like Haskell) would encourage similar patterns and use of closures. They do cause some overhead in JS, but this can theoretically be bypassed with smart compiling or preprocessing.
I think this is always a tradeoff, and for now we are forced to balance conciseness and clarity against performance. I would love to see an optimizing compiler that gets rid of extra allocations in the future, but it probably won't be soon.
That said, creating lambdas doesn't change much. We already re-create virtual DOM on each render (and also the props, nested objects inside the props, etc), which cause more allocations and GC runs than the lambdas.
I am all for zero-allocation style, but from my experience with web games, such optimizations make code much more bloated and less readable in general (this doesn't necessarily apply to React classes, which are still pretty clear). In React we don't run the rendering at 60 fps, so a bit of GC work is acceptable and usually not noticeable.