Skip to content

When might I want to use removeQueries instead of invalidateQueries and vice-versa #3169

Answered by TkDodo
Aaronius asked this question in Q&A
Discussion options

You must be logged in to vote

removeQueries has no effect on active queries. If a component re-renders for some reason that then tries to use the removed query, it will go into hard loading state again. Not sure why you'd ever want to remove an active query...

invalidateQueries is something completely different. It:

  • marks all matching queries as stale, so that they will be refetched the next time they are used
  • active queries will be immediately refetched per default (unless you change the options)

invalidation never removes something from the cache, it just refetches.

Replies: 3 comments 15 replies

Comment options

You must be logged in to vote
3 replies
@Aaronius
Comment options

@TkDodo
Comment options

@Aaronius
Comment options

Answer selected by Aaronius
Comment options

You must be logged in to vote
10 replies
@vincerubinetti
Comment options

@vincerubinetti
Comment options

@TkDodo
Comment options

@graup
Comment options

@TkDodo
Comment options

Comment options

You must be logged in to vote
2 replies
@ZeCarlosCoutinho
Comment options

@TkDodo
Comment options

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