DEV Community

Discussion on: React Hooks are a More Accurate Implementation of the React Mental Model

Collapse
 
gdeb profile image
Géry Debongnie

I believe that you are indeed exagerating. Hooks are wonderful, but you are trying too hard too make them look good.

My point is that yes, you are right in some way that react hooks are more declarative than class components, but only because react decided to cripple the hooks by not supporting class components

Weirdly, the React ecosystem decided that the proper reaction to that issue was to bash on class components for not being compatible with hooks instead of lamenting about the lack of class support for hooks.

But it is certainly possible to have hooks in class components (if the framework decides to implement it). And with those hooks, your two arguments against class would be nullified:

  1. the user state would be captured by the hook closure, so the component would not need to manage the saving operation
  2. the hook would register itself on the mounted/prop update lifecycle of the component, but with just one function without duplication, and properly isolated from the component.
Collapse
 
gdeb profile image
Géry Debongnie

by the way, sorry to react again to your posts. I just kind of enjoy the discussion about interesting points... Hope you don't take it as an attack or anything.