Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't know where your downvotes come from.

It's a different paradigm, and twisting hooks to behave like classes clearly doesn't work. I partially blame it on React not properly updating their hooks docs in time (they're 2.5y late, ffs).

Hooks are the way to go, class components should have died a fiery death back in 2018, and at this point any other opinion is just wrong.



> Hooks are the way to go, class components should have died a fiery death back in 2018, and at this point any other opinion is just wrong.

To your snarky comment, I'll raise my own snarky rant from a while ago, about hooks leading to render loops that are impossible to debug: https://blog.kronis.dev/everything%20is%20broken/modern-reac...

It's probably not the kind of writing that I'd strive for nowadays but the error message not telling me exactly where the problem is felt unacceptable and clicking on the error source leading me to React code instead of the problematic lines in my code felt just unnecessarily weird.

I know that hooks are touted as the best way to extract reusable bits of code, however when multiple useEffect hooks have issues with dependency arrays and start causing render loops, clearly something is wrong.

Personally, I acknowledge that class based components are an easier mental model for many out there, but are also dead due to the direction that React is heading in.

But I would also suggest that the new Vue Composition API does hooks better than React and that using Vue with Pinia (instead of React with Redux) will overcomplicate things way less for developers who just want to get things done.


Skimmed over your article. The infinite loop situation is not exclusive to hooks and very much exists in classes.

The situation is calling setState from useEffect, which triggers a render, triggers the setState, render, etc...

If you setState in componentDidUpdate without any guards you will end up with the same loop. I don't remember how debugging this worked, but I'm pretty sure it wasn't pretty.

As to big messy components: I don't think you can blame that on hooks. Hooks make it easier to split all of that up so you have isolated well contained chunks of logic that are much easier to test, debug, and manage.

Vue; not super familiar but I believe they use reactivity right? I think reactivity can be nice, but is also not as great as it's made out to be as it gets tricky as soon as you need to take control and prevent extra renders etc. A lot of it is making diffing and memoization less explicit, which can be nice, but also has some tradeoffs.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: