DEV Community

Discussion on: useAxios: React hook for any Axios call

Collapse
 
kwhitejr profile image
Kevin White

Can you point me to an example of a refresh function? This concept is new to me. Thanks for the advice!

Collapse
 
arieled91 profile image
Ariel • Edited

It's just an internal function that you can write inside your hook. It calls the axios function (again), and you have to return it without the '()', with the rest of the state values. So, from the ui you call it whenever you want to refresh.

//hook
const useExample = () => {
//state props
const refresh = () => {
// call axios impl
}
return {data, refresh}
}

//component
const [data, refresh] = useExample ()

button onClick={refresh}

I wrote this with my phone, sorry if it has a bug.

Thread Thread
 
kwhitejr profile image
Kevin White

Thank you! I'm following your pattern. Gonna meditate on it a while then refactor it in. Cheers!