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" },
});- ✓Correct answer: With
useMutationState, filtering by a sharedmutationKey - 2Mutations are only visible inside the component that called them
- 3By polling the server
Explanation
It reads the global mutation cache, enabling optimistic UI in places unrelated to the component that triggered the mutation.