T
TanStack14mo ago
broad-brown

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
itchy-amethyst
itchy-amethyst14mo ago
Filters | TanStack Query React Docs
Some methods within TanStack Query accept a QueryFilters or MutationFilters object. Query Filters
itchy-amethyst
itchy-amethyst14mo ago
queryKeys are hierarchal, so yes invalidating ['hello'] also invalidates ['hello', 'world']
broad-brown
broad-brownOP14mo ago
Tysm!
itchy-amethyst
itchy-amethyst14mo ago
To be clear, unless you use exact: true then yes they both invalidate

Did you find this page helpful?