I've also had doubts about hooks since its proposal, and I agree with the points you raised.
From the Rules of Hooks section in the documentation[0].
- React relies on the order in which Hooks are called.
- Only call Hooks at the top level. Don’t call Hooks inside loops, conditions, or nested functions.
- Only call Hooks from React function components. Don’t call Hooks from regular JavaScript functions.
This design decision doesn't sit well with me, and I won't be using it. However, the community seems to have already welcomed it, so I'm forced to learn the intricacies to be able to understand React codebases and keep up with the latest trend..
The addition of this feature is sure to increase cognitive load and technical debt. There are already countless variations of state management libraries and patterns that encourage pure functional components and decoupled logic. Hooks seem to be yet another opinionated strategy - and not for the best, in my view.
> However, the community seems to have already welcomed it, so I'm forced to learn the intricacies to be able to understand React codebases and keep up with the latest trend..
That's one thing that no many realizes: the JS community is special and you should take that in consideration when adding a new features.
When I say special, I mean it reacts (puns intended) in a way no other programming community does:
- it jumps on novelty with very little afterthoughs or regards for consequences.
- it has an habit of disregarding lessons from the past.
- it seldom fix problems, but add a new layer of solution on top of it.
Knowing this, the way hooks are released is too me like giving matches to children with the only advice "look how cool it is, I can make fireworks".
Yes, I'm exagerating for the argument sake. But still, react is now a software used everywhere, I'd welcome a switch from "move fast and break things" to "let's think this true" once in a while.
This is a good way to summarize the javascript community. Not learning from the past is possibly a side effect of being dominated by young and/or inexperienced programmers and being less inclined to research established concepts before making something up. Although there are plenty of benefits to younger programmers (I hope, I'm one myself), but there are drawbacks to everything.
From the Rules of Hooks section in the documentation[0].
- React relies on the order in which Hooks are called. - Only call Hooks at the top level. Don’t call Hooks inside loops, conditions, or nested functions. - Only call Hooks from React function components. Don’t call Hooks from regular JavaScript functions.
This design decision doesn't sit well with me, and I won't be using it. However, the community seems to have already welcomed it, so I'm forced to learn the intricacies to be able to understand React codebases and keep up with the latest trend..
The addition of this feature is sure to increase cognitive load and technical debt. There are already countless variations of state management libraries and patterns that encourage pure functional components and decoupled logic. Hooks seem to be yet another opinionated strategy - and not for the best, in my view.
---
[0] https://reactjs.org/docs/hooks-rules.html