공식문서 : https://tanstack.com/query/v4/docs/guides/filters
React Query내의 일부 메서드는 QueryFilters
또는 MutationFilter
객체를 허용한다.
Query Filters
query filter는 쿼리와 일치시킬 특정 조건을 가진 객체이다 :
// Cancel all queries
await queryClient.cancelQueries()
// Remove all inactive queries that begin with `posts` in the key
queryClient.removeQueries(['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(['posts'], { type: 'active' })
query filter 객체는 다음 속성을 지원한다 :
exact?:boolean
exact:true
옵션을 전달할 수 있다.type?:'active'|'inactive'|'all'
active
로 설정하면 active 쿼리들과 일치inactive
로 설정하면 inactive 쿼리들과 일치stale?:boolean
true
로 설정하면 stale 쿼리들과 일치false
로 설정하면 fresh 쿼리들과 일치fetchStatus?:FetchStatus
fetching
으로 설정하면 현재 fetch중인 쿼리들과 일치paused
로 설정하면 fetch하려고 했지만, 일시중지된 쿼리들과 일치idle
로 설정하면 fetch중이 아닌 쿼리들과 일치predicate?: (query: Query) => boolean
found
쿼리에 대해 참을 반환할 것으로 예상된다.queryKey?:QueryKey
Mutation Filters
mutation filter는 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 filter 객체는 다음 속성을 지원한다 :
exact?:boolean
exact:true
옵션을 전달할 수 있다.fetching?:boolean
true
로 설정하면 현재 fetch중인 mutation과 일치
false
로 설정하면 현재 fetch중이 아닌 mutation과 일치
predicate?: (mutation: Mutation) => boolean
found
mutation에 대해 참을 반환할것으로 예상된다.mutationKey?:MutationKey