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" },
],

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.

Further reading

Problem with a question

State Management · Senior · question 31

Test yourself

Take the State Management · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz