0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
query/docs/framework/vue/reference/functions/usePrefetchQuery.md
Wonsuk Choi d169ee8778
docs(*): add property tables and overload overviews to reference pages and keep declared alias names (#11758)
* docs(*): add parameter and result property tables to reference function pages and an overview to overloaded ones

* docs(*): link to the base type's properties when a parameter or result type has no property table

* docs(framework/*/reference): regenerate reference docs

* docs(framework/*/reference): regenerate reference docs

* chore(scripts/generate-docs): restore the 'dirname' import that the merge dropped

* docs(framework/*/reference): regenerate reference docs

* docs(scripts/generate-docs): label overloads in the overview with their declared parameter and return types

* docs(framework/*/reference): regenerate reference docs

* docs(scripts/generate-docs): convert declared intersection types from the source so signatures keep their alias names

* docs(framework/*/reference): regenerate reference docs

* docs(scripts/generate-docs): reword a comment to avoid the unknown word 'inlines'

* docs(scripts/generate-docs): skip a parameter table on overloaded pages when its heading is missing
2026-10-06 02:38:27 +09:00

2.7 KiB

id title redirect_from
usePrefetchQuery usePrefetchQuery
framework/vue/reference/usePrefetchQuery
function usePrefetchQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey>(options: MaybeRefOrGetter<MaybeRefDeep<UsePrefetchQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>>, queryClient?: QueryClient): void;

Defined in: packages/vue-query/src/usePrefetchQuery.ts:92

usePrefetchQuery does not return anything — it fires a prefetch as a reactive side effect, useful for kicking off a fetch ahead of the component that will actually render the data with useQuery. You can pass everything to usePrefetchQuery that you can pass to queryClient.query, though queryKey is always required, and queryFn is required unless a default query function has been defined.

The prefetch is skipped if the query already has any cached state — including a pending/error state left over from a previous attempt — so it won't refetch data that's already there or already in flight. It re-runs whenever a reactive dependency in options (built with queryOptions, for example) changes.

Fire this during render, before a suspense boundary that wraps a component using useQuery's suspense() — see the Suspense guide.

Type Parameters

TQueryFnData

TQueryFnData = unknown

TError

TError = Error

TData

TData = TQueryFnData

TQueryData

TQueryData = TQueryFnData

TQueryKey

TQueryKey extends readonly unknown[] = readonly unknown[]

Parameters

options

MaybeRefOrGetter<MaybeRefDeep<UsePrefetchQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>>

A ref, plain value, or reactive getter resolving to the UsePrefetchQueryOptions to use — everything you can pass to queryClient.query.

options properties

Built from QueryExecuteOptions. See the type above for what it changes.

queryClient?

QueryClient

Use this to use a custom QueryClient. Otherwise, the one provided by VueQueryPlugin will be used.

Returns

void

Example

<script setup lang="ts">
import { usePrefetchQuery } from '@tanstack/vue-query'
import Posts from './Posts.vue'

// Fire the prefetch as soon as this component runs, before `Posts` mounts and calls `useQuery`.
usePrefetchQuery({
  queryKey: ['posts'],
  queryFn: fetchPosts,
})
</script>

<template>
  <Posts />
</template>