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: invalidation & refetch

5 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.invalidateQueries behavior

queryClient.invalidateQueries marks matching queries as invalid and then refetches active queries by default. Takes filters (QueryFilters) and InvalidateOptions. By default uses refetchType: 'active' which refetches only active queries. With refetchType: 'none', queries are marked invalid but not refetched. With refetchType: 'all', all matching queries are refetched. With refetchType: 'inactive', only inactive queries are refetched. cancelRefetch defaults to true (cancels running requests before new request), throwOnError defaults to false.

Difference between invalidateQueries and refetchQueries

invalidateQueries marks matching queries as invalidated and then refetches active queries (unless refetchType is specified differently). refetchQueries refetches all matching queries without marking them invalid first. invalidateQueries keeps matching queries in the cache, while refetchQueries actually refetches them. Unlike refetchQueries, invalidateQueries has a refetchType option to control which queries are refetched.

queryClient.refetchQueries options

queryClient.refetchQueries takes filters (QueryFilters) and RefetchOptions. QueryFilters can include stale: true, queryKey, type: 'active'|'inactive'|'all', and exact boolean. RefetchOptions include throwOnError (defaults to false) and cancelRefetch (defaults to true). Returns a promise that resolves when all queries finish refetching.

queryClient.refetchQueries refetch conditions

Queries that are disabled because they only have disabled Observers will never be refetched. Queries that are static because they only have Observers with Static StaleTime will never be refetched.

queryClient.cancelQueries

queryClient.cancelQueries cancels outgoing queries based on their query keys or other functionally accessible properties. Takes filters (QueryFilters) and CancelOptions parameters. Does not return anything. Most useful for optimistic updates to prevent outgoing refetches from clobbering the optimistic update.

Give your agent this brain