Live data from Hacker News

Use Hooks – A Collection of Reusable React Hooks

use-hooks.org

21–30 of 34 posts

Re: Use Hooks – A Collection of Reusable React Hooks

#21

I’m having a hard time understanding what problems this (and hooks in general) really solve. Why should I use the axios hooks over just using axios directly?

The problem isn't using axios, it's making sure your React components interact with axios appropriately. You will want the request to (1) fire when the component mounts, (2) cancel if it's going to unmount, and (3) re-render with the result/error once the request is finished. This is a pattern you will do over and over again. This gets really messy when one component needs to be able to make two or three different ca…

And that is sort of solving a language verbosity problem with classes and inheritance and the fact that to mixin behaviors classically one would use inheritance but it doesnt compose well and had problems passing things up to different constructors.

Functions work better if you can call them because you can more easily select and add them ala carte and pass individual different specific parameters to each one whereas with inheritance you get one call to super (and advanced react components already extend a class further complicating super calls).

So it is best for one behavior having to only add something in one place to use that behavior. The class model fails because some behavior goes into ComponentDidMount and others go into ComponentWillUnmount and so on.

Hooks solve that. Everything required can be trvially bundled into one thing in one function call.

At first glance the biggest weakness I see for them is that they a bit too magical and that they operate at bit more dynamically than I think would be ideal. They rely on functions being called in the same order and waiting until functions are called for the first time, which seems like the opposite of “declarative”.

Having said that I’ve used them a bit and really like how much they cut down in boilerplate I just wish we had a something that felt a bit more like first class language supported (even if that support requires patching in something like jsx) I just don’t know how that would look or if it would look any different. It just feels like this is scratching deeper itch than just a react only problem but I can’t quite explain how (and maybe I am mistaken for that hunch). Maybe a more expressive language like a lisp would offer a hint at the solution.

Re: Use Hooks – A Collection of Reusable React Hooks

#23
post #18
post #16

Earlier quoted context omitted.

I disagree. That something is reusable is not enough for it to become a library. There should be other benefits, because, using an external library has its own drawbacks.

As someone who works for a popular consultancy that helps out developers at big companies and reviews their code: ANY library you can point people to and say "do it this way" is an absolute godsend. You really do not want large numbers of developers, with varying levels of experience, trying to figure out how to do something that has already been solved, and making the same avoidable mistakes in the process – unless…

I agree that “do it this way” can be godsend. However, suggesting a library is only one of the ways. By suggesting all these tiny libraries, I don’t think we will mentor the less experienced community in the right direction.

Re: Use Hooks – A Collection of Reusable React Hooks

#24
post #3

I’m having a hard time understanding what problems this (and hooks in general) really solve. Why should I use the axios hooks over just using axios directly?

Many front-end developers keep building the same thing over and over again with minor variations. To make the work feel more meaningful, it’s regularly reprojected onto a new pattern. Then you can go give a conference talk about “I did old thing X using new thing Y” and get away from the office for a day.

Seems like you just have an axe to grind. Hooks solve a lot of problems, and being ignorant to that doesn't make them useless :)

Re: Use Hooks – A Collection of Reusable React Hooks

#25
post #6

Earlier quoted context omitted.

If you haven't yet, I'd encourage you to seriously read through the hooks docs [0], as well as Dan Abramov's recent post discussing why they settled on this API design [1]. [0] https://reactjs.org/docs/hooks-intro.html [1] https://overreacted.io/why-do-hooks-rely-on-call-order/

I’ll dig into them. I skimmed them when hooks were first announced and felt like it was just a way to bolt on state to functional components. I should really revisit the intent of hooks.

The hooks docs are complete garbage. They don't explain anything properly and they use dumbed down language that ambiguates important details, in an attempt to make them more "accessible" to beginners (that somehow are too stupid to understand classes but can magically grasp these far more advanced concepts?).

Dan's blog post is much better, in comparison. Start with that maybe.

Re: Use Hooks – A Collection of Reusable React Hooks

#28
post #27
post #26

I’d like to see hooks in CRA but that’s apparently a CRA3.0 thing - far off in the future.

Spend an afternoon learning webpack, eject, and never look back :)

Ha, I went the exact opposite way — when I found out about CRA I was relieved to never have to deal with another webpack config :)

Re: Use Hooks – A Collection of Reusable React Hooks

#30
post #25

Earlier quoted context omitted.

I’ll dig into them. I skimmed them when hooks were first announced and felt like it was just a way to bolt on state to functional components. I should really revisit the intent of hooks.

The hooks docs are complete garbage. They don't explain anything properly and they use dumbed down language that ambiguates important details, in an attempt to make them more "accessible" to beginners (that somehow are too stupid to understand classes but can magically grasp these far more advanced concepts?). Dan's blog post is much better, in comparison. Start with that maybe.

If you think the docs can be improved, please submit PRs:

https://github.com/reactjs/reactjs.org

Post reply on HN