News for hackers. Stuff that matters.
Re:Is React impacted by Meta layoff? by SkyPuncher on Wednesday November 09, 2022 @11:32AM (#33533986)
I have come to prefer hooks, but I have never felt they're necessary. Class based React allowed for massive simplification of some setup/tear-down actions.
Re:Is React impacted by Meta layoff? by thebeastie on Wednesday November 09, 2022 @12:22PM (#33534793)
For someone to arrived late to the party, what’s better / simpler when using classes?
Re:Is React impacted by Meta layoff? by ajdegol on Wednesday November 09, 2022 @12:27PM (#33534888)
Depends on your use case; some things are easier as classes others as hooks.
Re:Is React impacted by Meta layoff? by notatoad on Wednesday November 09, 2022 @12:48PM (#33535230)
i'm a react noob too, but my impression is mostly that hooks are nicer for smaller components with simpler states, and classes reduce some boilerplate if you have a lot of different state variables within one component.
Re:Is React impacted by Meta layoff? by yamtaddle on Wednesday November 09, 2022 @01:16PM (#33535664)
Hook-using functions basically are classes, just with utterly bizarre method and property declaration syntax and some strange and unhelpful behaviors.

I mean, they ultimately associate lists of properties and functions (methods, if you like) with a component object instance (yes, object) down in the React internals. Sure, access to them is FIFO rather than a lookup table, but that still looks a whole lot like very-weird classes/objects being reimplemented in a language that already has decent-enough ones.

Now, the trouble was certain optimizations and features were probably going to be hard to impossible to achieve while supporting both functional- and class-based components more-or-less equally, and the easy path forward was to let class components become more powerful and functional components slip to second-class (haha), but instead they put object/class-like features in their functions so they could have functions (but very much stateful/side-effecty, so WTF is the point?) lead the way, for whatever reason.

Re:Is React impacted by Meta layoff? by SkyPuncher on Wednesday November 09, 2022 @07:37PM (#33540502)
Everything in hooks is explicit. Which is a blessing and a curse.

Classes were really easy to compose and automatically easily bring everything you needed into the class. This did lead to some situations where you could over-engineer and get yourself into a bind. You can technically do the same/similar thing with hooks, it just requires a bit more code. Lack of setup/tear down with hooks also means you need to rely on nonces more often.

In general, hooks have a bunch of small, reactive-programming tricks that you learn with experience.

Re:Is React impacted by Meta layoff? by barbecue_sauce on Wednesday November 09, 2022 @12:47PM (#33535204)
I stopped using React around the time hooks were introduced, and never figured out what problem they were supposed to solve.
Re:Is React impacted by Meta layoff? by cercatrova on Wednesday November 09, 2022 @02:58PM (#33537019)
I have something that has a lifecycle and I don't want to initialize and destroy the state every time. I encapsulate that into a function, call it a hook, and go about my day knowing that I don't have to care about redoing the lifecycle every single time.

It's basically a class that has pre-written lifecycle functions.