TanStack
API Reference

matchQuery

ts
function matchQuery(filters: QueryFilters, query: Query<any, any, any, any>): boolean;

Defined in: packages/query-core/src/utils.ts:205

Checks whether a query matches the given QueryFilters. Every filter that is specified must match; filters that are left unspecified are ignored.

Parameters

filters

QueryFilters

The filters to check the query against.

filters properties

PropertyTypeDefault valueDescription
exact?booleanundefinedMatch query key exactly
fetchStatus?"fetching" | "paused" | "idle"undefinedInclude queries matching their fetchStatus
predicate?(query: Query) => booleanundefinedInclude queries matching this predicate function
queryKey?TQueryKey | TuplePrefixes<TQueryKey>undefinedInclude queries matching this query key
stale?booleanundefinedInclude or exclude stale queries
type?QueryTypeFilter'all'Filter to active queries, inactive queries or all queries

query

Query<any, any, any, any>

The query to check.

Returns

boolean

true if the query matches every specified filter.

Example

ts
const queryCache = queryClient.getQueryCache()

const matchingQueries = queryCache
  .getAll()
  .filter((query) => matchQuery({ queryKey: ['posts'] }, query))