State Management · Senior · Question 33 of 75
How do you write the result of a mutation directly into a cached query without refetching (pessimistic update)?
- ✓Correct answer: Await
queryFulfilledinonQueryStarted, thenupdateQueryDatawith the response - 2Return the data from
invalidatesTags - 3Call the query hook inside the mutation
Explanation
A pessimistic update waits for the server and then patches the cache - no extra request, but the UI updates only after the response. Optimistic updates patch first and undo on failure.