Skip to content
Discussion options

You must be logged in to vote

there is. invalidateQueries also takes a predicate function as filter argument instead of the partial key. the example from the docs is:

 queryClient.invalidateQueries({
   predicate: query =>
     query.queryKey[0] === 'todos' && query.queryKey[1]?.version >= 10,
 })

if the function returns true, it will be invalidated, otherwise not.


you can achieve something similar with setQueryData if you don't want to invalidate by doing:

queryClient
  .getQueryCache()
  .findAll(filter)
  .forEach(({ queryKey }) => {
    queryClient.setQueryData(queryKey, newData)
  })

findAll takes the same filter (partial query key, predicate function) as invalidateQueries

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ryanmk54
Comment options

Answer selected by ryanmk54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants