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' })
查询过滤器对象支持以下属性
突变过滤器是具有特定条件以匹配突变的对象
// 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,
})
突变过滤器对象支持以下属性
const isMatching = matchQuery(filters, query)
const isMatching = matchQuery(filters, query)
返回一个布尔值,指示查询是否与提供的一组查询过滤器匹配。
const isMatching = matchMutation(filters, mutation)
const isMatching = matchMutation(filters, mutation)
返回一个布尔值,指示突变是否与提供的一组突变过滤器匹配。