I think you should delete any prop from useEffect dependencies array, that's causing the loops. Also it can be a good idea to export a refresh function, letting the ui decide when to call axios again.
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.
I think you should delete any prop from useEffect dependencies array, that's causing the loops. Also it can be a good idea to export a refresh function, letting the ui decide when to call axios again.
Can you point me to an example of a refresh function? This concept is new to me. Thanks for the advice!
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.
Thank you! I'm following your pattern. Gonna meditate on it a while then refactor it in. Cheers!