new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

TanStack Query · Reference · all subjects

queryclient methods

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

queryClient.fetchQuery method

fetchQuery is an asynchronous method that fetches and caches a query. It resolves with the data or throws with the error. If the query exists and data is not invalidated or older than the given staleTime, cached data is returned. Otherwise it fetches the latest data. Options are the same as useQuery except: enabled, refetchInterval, refetchIntervalInBackground, refetchOnWindowFocus, refetchOnReconnect, refetchOnMount, notifyOnChangeProps, throwOnError, select, suspense, and placeholderData are not available. Returns Promise<TData>.

queryClient.fetchInfiniteQuery method

fetchInfiniteQuery is similar to fetchQuery but fetches and caches an infinite query. Options are the same as fetchQuery. Returns Promise<InfiniteData<TData, TPageParam>>.

queryClient.prefetchQuery method

prefetchQuery is an asynchronous method that prefetches a query before it is needed or rendered with useQuery. Works the same as fetchQuery except it will not throw or return any data. Options are the same as fetchQuery. Returns Promise<void> that either immediately resolves if no fetch is needed or after the query has been executed.

queryClient.prefetchInfiniteQuery method

prefetchInfiniteQuery is similar to prefetchQuery but prefetches and caches an infinite query. Options are the same as fetchQuery. Returns Promise<void>.

queryClient.getQueryData method

getQueryData is a synchronous function that gets an existing query's cached data. Accepts queryKey parameter (QueryKey type). Returns data (TQueryFnData | undefined), or undefined if the query does not exist.

queryClient.ensureQueryData method

ensureQueryData is an asynchronous function that gets an existing query's cached data. If the query does not exist, queryClient.fetchQuery is called and results returned. Options include all fetchQuery options plus revalidateIfStale (optional, defaults to false). When revalidateIfStale is true, stale data is refetched in background but cached data returned immediately. Returns Promise<TData>.

queryClient.ensureInfiniteQueryData method

ensureInfiniteQueryData is an asynchronous function that gets an existing infinite query's cached data. If the query does not exist, queryClient.fetchInfiniteQuery is called and results returned. Options include all fetchInfiniteQuery options plus revalidateIfStale (optional, defaults to false). Returns Promise<InfiniteData<TData, TPageParam>>.

queryClient.getQueriesData method

getQueriesData is a synchronous function that gets cached data of multiple queries matching the passed filters. Accepts filters parameter (QueryFilters type). Returns [queryKey: QueryKey, data: TQueryFnData | undefined][], an array of tuples for matched query keys with their associated data, or empty array if no matches. The TData generic defaults to unknown due to varying data structures.

queryClient.setQueryData method

setQueryData is a synchronous function that immediately updates a query's cached data. If the query does not exist, it will be created. If the query is not utilized by a query hook within the default gcTime, the query will be garbage collected (defaults to 5 minutes if not configured). Accepts queryKey (QueryKey type) and updater (TQueryFnData | undefined | ((oldData: TQueryFnData | undefined) => TQueryFnData | undefined)). If non-function passed, data updates to that value. If function passed, receives old data and returns new data. If updater function returns undefined, data is not updated. Updates via setQueryData must be immutable—do not mutate oldData directly.

queryClient.getQueryState method

getQueryState is a synchronous function that gets an existing query's state. Accepts queryKey parameter (QueryKey type). Returns undefined if the query does not exist.

queryClient.setQueriesData method

setQueriesData is a synchronous function that immediately updates cached data of multiple queries by using filter function or partially matching query keys. Only queries matching the passed filters are updated; no new cache entries are created. Under the hood, setQueryData is called for each existing query. Accepts filters (QueryFilters type) and updater (TQueryFnData | (oldData: TQueryFnData | undefined) => TQueryFnData).

queryClient.invalidateQueries method

invalidateQueries invalidates and refetches single or multiple queries based on query keys or other properties. By default, all matching queries are immediately marked invalid and active queries are refetched in background. Options: filters (QueryFilters with optional refetchType field: 'active' (default), 'inactive', 'all', or 'none') and options (InvalidateOptions with throwOnError boolean and cancelRefetch boolean defaulting to true). When refetchType is 'active', only rendered queries refetch. When 'inactive', only non-rendered queries refetch. When 'all', all matching queries refetch. When 'none', no refetch occurs, queries only marked invalid. Unlike refetchQueries, invalidateQueries marks queries invalid then refetches active queries. Unlike removeQueries, invalidateQueries keeps matching queries in cache.

queryClient.refetchQueries method

refetchQueries refetches queries based on conditions. Accepts filters (QueryFilters type) and options (RefetchOptions with throwOnError boolean and cancelRefetch boolean defaulting to true). Returns a promise that resolves when all queries finish refetching. By default does not throw if refetches fail, but throws if throwOnError is true. Queries disabled due to only disabled Observers never refetch. Queries static due to Observers with static StaleTime never refetch. Unlike invalidateQueries, refetchQueries refetches all matching queries.

queryClient.cancelQueries method

cancelQueries cancels outgoing queries based on query keys or other properties. Most useful for optimistic updates to prevent outgoing refetches from clobbering optimistic updates when they resolve. Accepts filters (QueryFilters type) and cancelOptions (CancelOptions type). Returns nothing.

queryClient.removeQueries method

removeQueries removes queries from cache based on query keys or other properties. Accepts filters (QueryFilters type). Returns nothing. Unlike invalidateQueries and refetchQueries, removeQueries removes matching queries from cache instead of refetching them.

queryClient.resetQueries method

resetQueries resets queries in cache to initial state based on query keys or other properties. Notifies subscribers (unlike clear which removes all subscribers) and resets query to pre-loaded state (unlike invalidateQueries). If query has initialData, data resets to that. If query is active, it refetches. Accepts filters (QueryFilters type) and options (ResetOptions with throwOnError boolean and cancelRefetch boolean defaulting to true). Returns a promise that resolves when all active queries have been refetched.

queryClient.isFetching method

isFetching returns an integer representing how many queries in cache are currently fetching (including background-fetching, loading new pages, or loading more infinite query results). Accepts optional filters parameter (QueryFilters type). Returns the number of fetching queries.

queryClient.isMutating method

isMutating returns an integer representing how many mutations in cache are currently fetching. Accepts filters parameter (MutationFilters type). Returns the number of fetching mutations.

queryClient.getDefaultOptions method

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

queryClient.setDefaultOptions method

setDefaultOptions dynamically sets default options for the queryClient. Previously defined default options are overwritten.

queryClient.getQueryDefaults method

getQueryDefaults returns the default options that have been set for specific queries. If several query defaults match the given query key, they are merged together based on the order of registration.

queryClient.setQueryDefaults method

setQueryDefaults sets default options for specific queries. Accepts queryKey (QueryKey type) and options (QueryOptions type). Order of registration matters: registration should go from most generic key to least generic key so more specific defaults override more generic defaults.

queryClient.getMutationDefaults method

getMutationDefaults returns the default options that have been set for specific mutations. Accepts a mutation key.

queryClient.setMutationDefaults method

setMutationDefaults sets default options for specific mutations. Accepts mutationKey (unknown[] type) and options (MutationOptions type). Order of registration matters, similar to setQueryDefaults.

queryClient.getQueryCache method

getQueryCache returns the query cache this client is connected to.

queryClient.getMutationCache method

getMutationCache returns the mutation cache this client is connected to.

queryClient.clear method

clear clears all connected caches.

queryClient.resumePausedMutations method

resumePausedMutations resumes mutations that have been paused because there was no network connection.

Give your agent this brain