News for hackers. Stuff that matters.
Re:Facts every web dev should know before they burn out and ... by chakkepolja on Thursday October 21, 2021 @03:43PM (#28949891)
Tangential. I don't understand why class based react is disliked. Hooks are complex magic, and don't work like rest of language. Compared to that, class component will do exactly what you say.
Re:Facts every web dev should know before they burn out and ... by KronisLV on Thursday October 21, 2021 @03:59PM (#28950101)
I actually agree with this and liked when you could see the full behaviour of a particular concern within a component, for example, its shouldComponentUpdate() method.

But now, with hooks, you might instead have 3 or 4 useState hooks, each of which could cause a component update. Worse yet, with useEffect hooks, you might run into the interdependent dependency array problem, which would cause a refresh loop.

Now it feels like your components have now become containers for smaller loosely coupled units of code with their own behaviour and life cycles, all of which may result in lower coherency as well.

I actually voiced some of my concerns a while ago in a slightly satirical portion of my blog, called "Everything is Broken": https://blog.kronis.dev/everything%20is%20broken/modern-reac...

Re:Facts every web dev should know before they burn out and ... by Chyzwar on Friday October 22, 2021 @05:11AM (#28955128)
Once you grok hooks, they are just better.

With hooks, it is easy to create re-usable state controllers than with class based components. Components that use hooks are easier to read, understand and modify. Hooks are also easier to test and annotate with typescript.

In classical class based component you would often have complicated code in componentDidUpdate, componentDidMount or getDerivedStateFromProps. Code ended being complex and interaction between lifecycle methods and constructor hard to debug.

Re:Facts every web dev should know before they burn out and ... by KronisLV on Friday October 22, 2021 @03:40PM (#28961683)
> Once you grok hooks, they are just better.

Disagreed. It's likely that there are factors at play here that we're not considering, such as personal preference or certain people enjoying different patterns more.

> Components that use hooks are easier to read, understand and modify.

Hard disagree. In my experience, hooks take a single concern within a component (whether it should update, or reacting to a certain event within it) and scatter the logic throughout multiple hooks in any non-trivial application, which leads to the control flow becoming harder to understand and lower overall coherency of the code.

> In classical class based component you would often have complicated code in componentDidUpdate, componentDidMount or getDerivedStateFromProps.

This feels like an indicator that you should split your components into smaller parts and compose those, as opposed to look for other ways which may or may not be better (because of the aforementioned differing preferences) to express that same level of complexity.

> Code ended being complex and interaction between lifecycle methods and constructor hard to debug.

I apply this very same quality to hooks.