T
TanStack17mo ago
ambitious-aqua

Does partial matching apply to query keys?

For invalidateQueries, do query keys just need to meet the subset of query keys or must it be exact. For example, if i have two queries that have the following queryKeys: ['hello'] and ['hello', 'world'] would invalidating ['hello'] invalidate both of the queries? I assume not since queryKeys are hashed at some point?
4 Replies
protestant-coral
protestant-coral17mo ago
Filters | TanStack Query React Docs
Some methods within TanStack Query accept a QueryFilters or MutationFilters object. Query Filters
protestant-coral
protestant-coral17mo ago
queryKeys are hierarchal, so yes invalidating ['hello'] also invalidates ['hello', 'world']
ambitious-aqua
ambitious-aquaOP17mo ago
Tysm!
protestant-coral
protestant-coral17mo ago
To be clear, unless you use exact: true then yes they both invalidate

Did you find this page helpful?