UNPKG

@tanstack/vue-query

Version:

Hooks for managing, caching and syncing asynchronous and remote data in Vue

30 lines 1.05 kB
// src/usePrefetchInfiniteQuery.ts import { getCurrentScope, unref, watchEffect } from "vue-demi"; import { useQueryClient } from "./useQueryClient.js"; import { cloneDeepUnref } from "./utils.js"; function isGetter(value) { return typeof value === "function"; } function usePrefetchInfiniteQuery(options, 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(); watchEffect(() => { const resolvedOptions = isGetter(options) ? options() : unref(options); const clonedOptions = cloneDeepUnref(resolvedOptions); if (!client.getQueryState(clonedOptions.queryKey)) { void client.prefetchInfiniteQuery( clonedOptions ); } }); } export { usePrefetchInfiniteQuery }; //# sourceMappingURL=usePrefetchInfiniteQuery.js.map