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/[deleted] Apr 26 '19 edited Apr 26 '19
In FP languages closures are created out of necessity, be it for code organization or to pass the context. Closures, as shown in react hooks docs, seem to be created for stylistic and ergonomic reasons, and it's not even a good style. It gets noisy pretty quickly when you have several hooks.
I don't see the equivalency between virtual-dom or props allocation and these hook closures allocation because it's inherence in the dom diffing algorithm that diffing may result in nothing changed and all the diffing work is wasted, it's necessary to clone props to ensure immutability, etc. On the other hand, the hook thing is really just for the convenience of having everything in a function. It's not necessary to have a hook API like that. As someone here mentioned, a hypothetical class-based hook API would be able to provide the same mechanism.
I've never worked on a library or a framework, most of my work has been in non-performance-critical software fortunately so I've been pretty negligent about perf. However, I think people use foundational libraries like react for all sort of thing so it should be treated as performance-critical software.