React · Middle · Question 37 of 75
How does RTK Query know which data to refetch after a mutation?
- ✓Correct answer: Query endpoints declare
providesTags, and mutations declareinvalidatesTags - 2It refetches all endpoints after any mutation
- 3You have to call
refetch()on every query hook manually
Explanation
Tags link the query cache to mutations: getPosts provides [{ type: 'Post', id: 'LIST' }], and addPost invalidates the Post tag - active queries with this tag are refetched automatically. It's the counterpart of invalidateQueries in TanStack Query.