State Management · Senior · Question 31 of 75
How does RTK Query decide which tagged queries to refetch with id-level tags?
providesTags: (result) => [
...(result?.map(({ id }) => ({ type: "Post" as const, id })) ?? []),
{ type: "Post", id: "LIST" },
],- ✓Correct answer: A mutation invalidating
{ type: 'Post', id: 5 }refetches only queries providing that tag - 2Any mutation refetches every query that provides any
Posttag - 3Tags with ids are ignored and only the type matters
Explanation
Editing post 5 invalidates { type: 'Post', id: 5 } (detail and lists containing it), while adding a post invalidates { type: 'Post', id: 'LIST' }. Fine-grained tags avoid refetching everything.