
Some methods within React Query accept a QueryFilters or MutationFilters object.
Query FiltersA query filter is an object with certain conditions to match a query with:
// Cancel all queriesawait queryClient.cancelQueries()// Remove all inactive queries that begin with `posts` in the keyqueryClient.removeQueries(['posts'], { type: 'inactive' })// Refetch all active queriesawait queryClient.refetchQueries({ type: 'active' })// Refetch all active queries that begin with `posts` in the keyawait queryClient.refetchQueries(['posts'], { type: 'active' })
A query filter object supports the following properties:
exact?: booleanexact: true option to return only the query with the exact query key you have passed.type?: 'active' | 'inactive' | 'all'allactive it will match active queries.inactive it will match inactive queries.stale?: booleantrue it will match stale queries.false it will match fresh queries.fetchStatus?: FetchStatusfetching it will match queries that are currently fetching.paused it will match queries that wanted to fetch, but have been paused.idle it will match queries that are not fetching.predicate?: (query: Query) => booleanfound.queryKey?: QueryKeyMutation FiltersA 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?: booleanexact: true option to return only the mutation with the exact mutation key you have passed.fetching?: booleantrue it will match mutations that are currently fetching.false it will match mutations that are not fetching.predicate?: (mutation: Mutation) => booleanfound.mutationKey?: MutationKeyThe best JavaScript newsletter! Delivered every Monday to over 76,000 devs.