@tanstack/vue-query
Version:
Hooks for managing, caching and syncing asynchronous and remote data in Vue
29 lines • 1.07 kB
JavaScript
// src/useIsFetching.ts
import { getCurrentScope, onScopeDispose, ref, watchEffect } from "vue-demi";
import { useQueryClient } from "./useQueryClient.js";
import { cloneDeepUnref } from "./utils.js";
function useIsFetching(fetchingFilters = {}, queryClient) {
if (process.env.NODE_ENV === "development") {
if (!getCurrentScope()) {
console.warn(
'vue-query composable like "useQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
);
}
}
const client = queryClient || useQueryClient();
const isFetching = ref();
const listener = () => {
const resolvedFilters = typeof fetchingFilters === "function" ? fetchingFilters() : fetchingFilters;
isFetching.value = client.isFetching(cloneDeepUnref(resolvedFilters));
};
const unsubscribe = client.getQueryCache().subscribe(listener);
watchEffect(listener);
onScopeDispose(() => {
unsubscribe();
});
return isFetching;
}
export {
useIsFetching
};
//# sourceMappingURL=useIsFetching.js.map