State Management · Middle · Question 34 of 75

How do you make an RTK Query mutation refetch the post list?

getPosts: build.query({ query: () => "posts", providesTags: ["Post"] }),
addPost: build.mutation({ query: (body) => ({ url: "posts", method: "POST", body }) }),

Explanation

Tags link the cache to mutations. For finer control, tag items by id ({ type: 'Post', id }) plus a 'LIST' tag, so editing one post refetches only what's affected.

Further reading

Problem with a question

State Management · Middle · question 34

Test yourself

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

Take this quiz