@tanstack/vue-query
Version:
Hooks for managing, caching and syncing asynchronous and remote data in Vue
28 lines • 992 B
JavaScript
// src/usePrefetchQuery.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 usePrefetchQuery(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.prefetchQuery(clonedOptions);
}
});
}
export {
usePrefetchQuery
};
//# sourceMappingURL=usePrefetchQuery.js.map