TanStack Query 내의 일부 메서드는 QueryFilters 또는 MutationFilters 객체를 받습니다.
Query Filters쿼리 필터는 쿼리와 일치시킬 특정 조건이 있는 객체입니다:
// 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' })
쿼리 필터 객체는 다음과 같은 프로퍼티들을 지원합니다:
queryKey?: QueryKeyexact?: booleanexact: true 옵션을 전달하여 전달한 정확한 쿼리 키가 포함된 쿼리만 반환할 수 있습니다.type?: 'active' | 'inactive' | 'all'all입니다.active로 설정하면 active 쿼리와 일치합니다.inactive로 설정하면 inactive 쿼리와 일치합니다.stale?: booleantrue로 설정하면 stale 쿼리와 일치시킵니다.false로 설정하면 새 쿼리와 일치시킵니다.fetchStatus?: FetchStatusfetching으로 설정하면 현재 fetching 중인 쿼리와 일치시킵니다.paused로 설정하면 fetch를 원하지만 일시 중지된 쿼리와 일치시킵니다.idle로 설정하면 fetch되지 않은 쿼리와 일치시킵니다.predicate?: (query: Query) => booleanMutation FiltersMutation 필터는 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.options.variables?.id === 1,
})
mutation 필터 객체는 다음과 같은 프로퍼티들을 지원합니다:
mutationKey?: MutationKeyexact?: booleanexact: true 옵션을 전달하여 정확한 mutation 키가 있는 mutation만 리턴할 수 있습니다.fetching?: booleantrue로 설정하면 현재 fetching 중인 mutations와 일치시킵니다.false로 설정하면 fetch하지 않은 mutations와 일치시킵니다.predicate?: (mutation: Mutation) => booleanReference