I'm looking for a solution on how to fire function when all requests have been finished.
I'm using React Query to manage external data state and useMutation
hook because I need to re-fetch data on select change.
const fetcher1 = async () => await axios.get('XXX');
const fetcher2 = async () => await axios.get('XXX');
const { data, isLoading, mutate: fetchData1 } = useMutation(fetcher1)
const { data2, isLoading: isLoading2, mutate: fetchData2 } = useMutation(fetcher2)
function runWhenReady() {
console.log("Ready!")
}
// re-fetch on select change and initial fetch
useEffect(() => {
fetchData1();
fetchData2();
}, [selectValueChanged])
I want to watch for request state change and fire runWhenReady()
when all of the requests are not pending. I suppose I need to wait for e.g 1s to make a decision.
Could anyone help me with preparing utility to monitor request states? Thanks!