Capítulo 27 de 80
queryClient.invalidateQueries({ queryKey }) marks matching queries stale (overriding any configured staleTime) and, if currently rendered, triggers an immediate background refetch — matching is by key prefix by default, so ['todos'] invalidates ['todos'], ['todos', {page: 1}], and every other query starting with 'todos'.
staleTime), and if it has active observers (currently rendered via useQuery), it's refetched in the background immediately rather than waiting for the next natural trigger.invalidateQueries({ queryKey: ['todos'] }) matches every query whose key starts with ['todos'], not just an exact match — ['todos', { page: 1 }] is included.['todos', { type: 'done' }]) to only match that shape and its extensions; pass exact: true to match only the given key with no extra segments at all.invalidateQueries({ predicate: (query) => ... }) receives every cached Query instance and lets you return true/false per query — e.g. invalidate only todos queries with version >= 10.queryClient.invalidateQueries() with no arguments invalidates every query in the cache.setQueryData) as the two supported update strategies.// Prefix match — invalidates ['todos'] and ['todos', {page:1}] alike
queryClient.invalidateQueries({ queryKey: ['todos'] })
// Exact match only — does NOT invalidate ['todos', {type:'done'}]
queryClient.invalidateQueries({ queryKey: ['todos'], exact: true })
// Predicate — arbitrary custom matching logic
queryClient.invalidateQueries({
predicate: (query) => query.queryKey[0] === 'todos' && query.queryKey[1]?.version >= 10,
})
invalidateQueries call.exact: true only when you specifically must not touch derived/filtered variants.predicate is the escape hatch for matching logic that key-prefix alone can't express (e.g. numeric comparisons on key segments).setQueryData writes (Chapter 29) when refetching is provably too slow or unnecessary for a specific case.onSuccess).queryKey, exact, predicate, etc.) reused across invalidateQueries, removeQueries, and other bulk cache operations.