new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

TanStack Query · Reference · all subjects

queryclient methods: query defaults

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Default query function example with QueryClient

A default query function can be defined to receive the query key and handle API requests uniformly across the application. The function is provided to QueryClient via defaultOptions.queries.queryFn. In the example, a QueryFunction is defined that receives queryKey and makes an axios GET request to jsonplaceholder.typicode.com using the first element of the queryKey as the path. The QueryClient is then instantiated with this default function, and provided to the Angular application via provideTanStackQuery().

queryClient.getDefaultOptions

queryClient.getDefaultOptions returns the default options which have been set when creating the client or with setDefaultOptions.

queryClient.setDefaultOptions

queryClient.setDefaultOptions can be used to dynamically set the default options for this queryClient. Previously defined default options will be overwritten. Example: queryClient.setDefaultOptions({ queries: { staleTime: Infinity } })

queryClient.getQueryDefaults

queryClient.getQueryDefaults returns the default options which have been set for specific queries using setQueryDefaults. If several query defaults match the given query key, they will be merged together based on the order of registration.

queryClient.setQueryDefaults

queryClient.setQueryDefaults sets default options for specific queries. Takes queryKey (QueryKey) and options (QueryOptions) parameters. Example: queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts }). Registration order matters: register from most generic key to least generic key so specific defaults override generic defaults. Merged defaults are based on registration order.

queryClient.getMutationDefaults

queryClient.getMutationDefaults returns the default options which have been set for specific mutations using setMutationDefaults.

queryClient.setMutationDefaults

queryClient.setMutationDefaults sets default options for specific mutations. Takes mutationKey (unknown[]) and options (MutationOptions) parameters. Example: queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost }). Registration order matters similar to setQueryDefaults.

Give your agent this brain