State Management · Middle · Question 74 of 75

How can a header badge show all pending "add to cart" mutations from other components?

const pending = useMutationState({
  filters: { mutationKey: ["addToCart"], status: "pending" },
});

Explanation

It reads the global mutation cache, enabling optimistic UI in places unrelated to the component that triggered the mutation.

Further reading

Problem with a question

State Management · Middle · question 74

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