Some methods within React Query accept a QueryFilters
or MutationFilters
object.
Query Filters
A query filter is an object with certain conditions to match a query with:
// Cancel all queriesawait queryClient.cancelQueries()// Remove all inactive queriesqueryClient.removeQueries('posts', { inactive: true })// Refetch all active queriesawait queryClient.refetchQueries({ active: true })// Refetch all active queries that begin with `post` in the keyawait queryClient.refetchQueries('posts', { active: true })
A query filter object supports the following properties:
exact?: boolean
exact: true
option to return only the query with the exact query key you have passed.active?: boolean
true
it will match active queries.false
it will match inactive queries.inactive?: boolean
true
it will match inactive queries.false
it will match active queries.stale?: boolean
true
it will match stale queries.false
it will match fresh queries.fetching?: boolean
true
it will match queries that are currently fetching.false
it will match queries that are not fetching.predicate?: (query: Query) => boolean
found
.queryKey?: QueryKey
Mutation Filters
A mutation filter is an object with certain conditions to match a mutation with:
// Get the number of all fetching mutationsawait queryClient.isMutating()// Filter mutations by mutationKeyawait queryClient.isMutating({ mutationKey: "post" })// Filter mutations using a predicate functionawait queryClient.isMutating({ predicate: (mutation) => mutation.options.variables?.id === 1 })
A mutation filter object supports the following properties:
exact?: boolean
exact: true
option to return only the mutation with the exact mutation key you have passed.fetching?: boolean
true
it will match mutations that are currently fetching.false
it will match mutations that are not fetching.predicate?: (mutation: Mutation) => boolean
found
.mutationKey?: MutationKey
The latest TanStack news, articles, and resources, sent to your inbox.