DEV Community

Discussion on: Constructors in Functional Components With Hooks

Collapse
 
devhammed profile image
Hammed Oyedele

Okay and funny enough, I use closures a lot of time e.g in factory functions.

Thread Thread
 
bytebodger profile image
Adam Nathaniel Davis

And that's why I said that I consider the Hooks documentation regarding constructors to be arrogant. It starts from the (false) assumption that there's only one reason to ever need/use a constructor (to initialize state) and then it doubles down on that folly by stating that there's simply no need for them anymore.

With closures, I'm sure there are many devs out there like me who aren't using them often (or at all) in their code. That doesn't mean that we should make a global statement that they're not needed. And we definitely shouldn't do anything to remove support for them.

Thread Thread
 
peerreynders profile image
peerreynders • Edited

Ryan Carniato (SolidJS, MarkoJS) notes in: React Hooks: Has React Jumped the Shark? (Feb 2019):

The challenge here is, to use Hooks beyond simple scenarios requires you to be a competent JavaScript developer. And I don’t mean this in any way a slight. But if you are having issues with this or bind with Classes, Hooks are no simpler. Hooks force you to really understand closures, reference vs value types, and memoization, and more importantly have a keen eye (or linter) to make sure you do not miss any small piece required to make them work.

He has a number of other pro-Hook (but not fanboyish) articles:

That last one explains where hooks do make sense.

The fit with React at this point is somewhat awkward - one has to wonder whether React is maneuvering into a position where ditching the VDOM becomes an option (to replace it with modern Fine-Grained change detection).

Thread Thread
 
bytebodger profile image
Adam Nathaniel Davis

Oooh... these links look awesome. In particular, I love love LOVE the assessment that "Hooks are no simpler". I think this speaks to some of the frustration I've had with them, literally since the day they were announced. I'm not anti-Hooks. In fact, all of my current React dev is now Hooks-based. But I'm continually annoyed by some fanboys who act as though Hooks are self-evidently better, and everything else is clearly worse. They act as though the answer to, "Why Hooks?" is "Well... Hooks!!!"

The historical perspective in these articles is also awesome. I've made a few references in my previous articles to Knockout. It's amazing (to me) how many "senior" JS devs today don't even know what Knockout was/is. This author seems to have a very well-rounded approach to the whole thing.

Thread Thread
 
peerreynders profile image
peerreynders

I needed Deep dive: How do React hooks really work? (2019) before hooks made sense to me.