DEV Community

Easily fetch data: react-api-hook

Michele on April 30, 2021

When developing a complex web app with React, the best thing is modularise and break up the code in smaller components, hooks or functions. So our ...
Collapse
 
pavermakov profile image
Pavel Ermakov

Add a few more requests and turn your components into an unreadable mess.

Collapse
 
demicdev profile image
Michele

What do you mean?

Collapse
 
pavermakov profile image
Pavel Ermakov

Can you run multiple requests in parallel? Can you chain one request to another?

Thread Thread
 
demicdev profile image
Michele

If you have to run multiple request, you only have to declare another hook:

const [stateFirst, sendFirst, cancelFirst] = useAPIHook(ENDPOINT1, configFirst);
const [stateSecond, sendSecond, cancelSecond] = useAPIHook(ENDPOINT2, configSecond);
Enter fullscreen mode Exit fullscreen mode