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

Don't get me wrong, I love hooks because I know how to use them, but there's so many easy pitfalls with them, and I constantly have to pester people about them in code reviews, if so many people in my company (and wider) misuse them by accident, it makes me me doubt how well thought out they are.

I know some people have a thing for arcane programming (for a lack of better word), but in my opinion it just makes code harder to write, understand, and even statically analyse.

Not to mention, the official lining for hooks leaves a lot to be desired for, especially because some internal React return values are treated magically by the linter (useState, useReducer to name a few) when it comes to hook dependency management.



I came across this problem the other day:

https://stackoverflow.com/questions/53332321/react-hook-warn...

I love React and my first experience with hooks has been mostly positive, but how is it that something as simple as data fetching is not completely sorted out by now?

It sounds abhorrent!


For a deep dive: https://dev.to/n1ru4l/homebrew-react-hooks-useasynceffect-or...

I think the current best answer is https://github.com/n1ru4l/use-async-effect

But as noted by your SO question, Suspense for data fetching is what we're waiting for. It was originally scheduled to be released the middle of this year but was delayed. https://reactjs.org/blog/2019/08/08/react-v16.9.0.html#an-up...


I'd say for 95% of data fetches https://github.com/slorber/react-async-hook works really well without needing generator syntax or explicit promise cancellation boilerplate. I'm not the author but a satisfied user.




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

Search: