DEV Community

Discussion on: useAxios : A simple custom hook for calling APIs using axios

Collapse
 
dougantr profile image
Douglas Trofino

Nice hook!
I will try that in my projects. Thank you for sharing!
I just would return the hooks states as an array, so I can rename it.

return [ response, error, loading ];

const [ products, productsError, productsLoading ] = useAxios(params);

In case a I need more than one api request in the same component, I can differentiate them.

Collapse
 
hey_yogini profile image
Yogini Bende

Hey, that's a nice improvement!

Collapse
 
steventhan profile image
Steven Than

You can rename with object returns as well

const { response: products, loading: productsLoading, error: productsError } = useAxios(...)
Enter fullscreen mode Exit fullscreen mode

Some comments have been hidden by the post's author - find out more