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.
Use Hooks – A Collection of Reusable React Hooks
11–20 of 34 posts
Re: Use Hooks – A Collection of Reusable React Hooks
#12Hooks are interesting. We are reading about it and evaluating it. However, I have a hard time in understanding why I should use all these tiny ‘use’ libraries? Hooks are already simple to implement such small snippets yourself in your codebase.
Re: Use Hooks – A Collection of Reusable React Hooks
#13I’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?
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/
Re: Use Hooks – A Collection of Reusable React Hooks
#14I like https://www.hooks.guide/ way more as it provides both usage + implementation of many different hooks from the community.
Re: Use Hooks – A Collection of Reusable React Hooks
#15I’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.
Re: Use Hooks – A Collection of Reusable React Hooks
#16Hooks are interesting. We are reading about it and evaluating it. However, I have a hard time in understanding why I should use all these tiny ‘use’ libraries? Hooks are already simple to implement such small snippets yourself in your codebase.
Because it's reusable, you can apply it in more projects than one. In another way, if a Hooks includes business logic, then it should be put in your project.
Re: Use Hooks – A Collection of Reusable React Hooks
#17I’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?
Reusability, which software folks generally consider to be a good thing. Let's say you used Axios directly in your components. That means every component needs to (1) set up its own state to track the request status (like whether it's loading, errored, the latest payload, etc.) and (2) set up its lifecycle hooks to kick off the request at the appropriate times, update the component's state, etc. Do this a few times a…
Re: Use Hooks – A Collection of Reusable React Hooks
#18Earlier quoted context omitted.
Because it's reusable, you can apply it in more projects than one. In another way, if a Hooks includes business logic, then it should be put in your project.
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.
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 you are deliberately trying to teach them something at that moment (whereas most of the time they are just trying to get things done on a tight schedule).
The job of a developer is only secondarily to write code. The primary job is to fulfill the actual real-world needs of their business or organization. Customers don't want code, they just want their needs met. Unfortunately sometimes this involves barfing out a lot of code – which is more likely a liability, not an asset to the company. The more new code we can avoid bringing into the world, the better.
Re: Use Hooks – A Collection of Reusable React Hooks
#19This is just...a mostly empty landing page? I like https://www.hooks.guide/ way more as it provides both usage + implementation of many different hooks from the community.
https://use-hooks.org/ is actually an entry of GitHub Organization https://github.com/use-hooks, it aims for creating custom hooks easily and putting in one place.
Re: Use Hooks – A Collection of Reusable React Hooks
#20Earlier quoted context omitted.
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…
Ah interesting and makes a lot of sense. I’m used to using redux with some other middleware to solve this problem and honestly I’ve never been happy with it. Thanks for the response!