News for hackers. Stuff that matters.
Re:Introducing Hooks by bendavis381 on Thursday October 25, 2018 @02:34PM (#18303343)
I agree. Optimizing a developer library for developers who struggle to understand what a class is seems like a good way to build something very convoluted.
Re:Introducing Hooks by ergothus on Thursday October 25, 2018 @04:05PM (#18304130)
I don't think the issue is "what is a class". It's more that the lifecycle functions get tied into the class, and you end up with a ball of highly conditional logic. It's easy for newbies to just add stuff to make it work, but end up with a mess.

React is the view layer, so the class concept of "here's some data and methods to alter it" doesn't really match with what happens - I don't know that components every should have been classes in the first place.

Re:Introducing Hooks by xab9 on Thursday October 25, 2018 @04:58PM (#18304533)
According to the article yes, the issue is "what is a class":

"You have to understand how this works in JavaScript, which is very different from how it works in most languages. You have to remember to bind the event handlers." etc.

Re:Introducing Hooks by wild_preference on Thursday October 25, 2018 @06:02PM (#18304972)
Eh, even in the same paragraph it says "The distinction between function and class components in React and when to use each one leads to disagreements even between experienced React developers."

Also, bits of class issues show up in the other complaints.

So, no, it's not just "what is a class" and it's a weird hill to die on. I feel like most of these responses to hooks in general just focus on the most trivial detail aka bikeshedding.

Re:Introducing Hooks by xab9 on Friday October 26, 2018 @01:33AM (#18307009)
I'm focusing on classes, because it seems to me that to "React" classes are a necessary evil (or they are treating them like they were).

Hooks, suspense, context wormholes - I'm not sure if these features should be part of a view engine. React, to me, did one thing and did it well, but now... I don't know.

Re:Introducing Hooks by ergothus on Thursday October 25, 2018 @05:16PM (#18304647)
Can't argue with the text of the article. I do, however, stand by why _I_ have found that classes are a bad match for this need, and watching the video of the demo did a much better job of suggesting the benefits and reasoning...reasons that don't really match the parts of the article you've quoted.

https://www.youtube.com/watch?v=kz3nVya45uQ&t=39m (from elsewhere in the comments here)

Re:Introducing Hooks by visarga on Friday October 26, 2018 @02:36AM (#18307220)
>Video unavailable. This video contains content from WebTVAsia (Music), who has blocked it on copyright grounds.

LOL, did they just block a video presentation for some incidental random music in the background?

Re:Introducing Hooks by Vinnl on Friday October 26, 2018 @03:05AM (#18307316)
It's not just having to understand what a class is, it's also having to know and remember to add a constructor to your class just to call `this.handleSomeEvent = this.handleSomeEvent.bind(this)`.

Sure, I know what it does and why it is needed, but it is ugly, cumbersome, and I keep forgetting it nonetheless.

Re:Introducing Hooks by beaconstudios on Friday October 26, 2018 @06:05AM (#18307971)
Re:Introducing Hooks by tracker1 on Thursday October 25, 2018 @08:16PM (#18305786)
There are other ways to approach an issue beyond shoving everything into a class. I'm not sure I really like the new hooks over the state methods at that level since I tend to separate global state (redux) vs component state (class) vs component state rendering (functional component).

In the end it depends on your style. I think this might be useful in a way that can be more pure than some other methods might be.

Re:Introducing Hooks by AlexCoventry on Thursday October 25, 2018 @11:25PM (#18306542)
I don't know what you mean by pure. There is nothing reverentially transparent about the new API. (Nor can there be, really.)
Re:Introducing Hooks by tracker1 on Sunday October 28, 2018 @07:39PM (#18323915)
And nothing that requires you to use the new API.