TanStack Query 中的某些方法接受 QueryFilters 或 MutationFilters 对象。
查询过滤器是一个对象,其中包含用于匹配查询的特定条件
// Cancel all queries
await queryClient.cancelQueries()
// Remove all inactive queries that begin with `posts` in the key
queryClient.removeQueries({ queryKey: ['posts'], type: 'inactive' })
// Refetch all active queries
await queryClient.refetchQueries({ type: 'active' })
// Refetch all active queries that begin with `posts` in the key
await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })
// Cancel all queries
await queryClient.cancelQueries()
// Remove all inactive queries that begin with `posts` in the key
queryClient.removeQueries({ queryKey: ['posts'], type: 'inactive' })
// Refetch all active queries
await queryClient.refetchQueries({ type: 'active' })
// Refetch all active queries that begin with `posts` in the key
await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })
查询过滤器对象支持以下属性
mutation 过滤器是一个对象,其中包含用于匹配 mutation 的特定条件
// Get the number of all fetching mutations
await queryClient.isMutating()
// Filter mutations by mutationKey
await queryClient.isMutating({ mutationKey: ['post'] })
// Filter mutations using a predicate function
await queryClient.isMutating({
predicate: (mutation) => mutation.state.variables?.id === 1,
})
// Get the number of all fetching mutations
await queryClient.isMutating()
// Filter mutations by mutationKey
await queryClient.isMutating({ mutationKey: ['post'] })
// Filter mutations using a predicate function
await queryClient.isMutating({
predicate: (mutation) => mutation.state.variables?.id === 1,
})
mutation 过滤器对象支持以下属性
const isMatching = matchQuery(filters, query)
const isMatching = matchQuery(filters, query)
返回一个布尔值,指示查询是否与提供的查询过滤器集匹配。
const isMatching = matchMutation(filters, mutation)
const isMatching = matchMutation(filters, mutation)
返回一个布尔值,指示 mutation 是否与提供的 mutation 过滤器集匹配。