Hacker News new | ask | show | jobs
by exogen 2748 days ago
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 and you'll notice things becoming very repetitive. So naturally you look for a way to factor that out.

A higher-order component (basically a function that generates a component with all that boilerplate) is one option. Another option is what you see here – Hooks.

1 comments

Yeah I’ve dealt with the repetition and boilerplate, but maybe I’m not working in react apps of significant size. I should really revisit hooks and understand them better.