mutation lifecycle callbacks
The functions TanStack Query calls at each stage of a mutation: onMutate before it is sent, onSuccess or onError after, and onSettled at the very end.
In more detail
onMutate applies the optimistic change and returns context such as { previousData }; onError receives that context and restores it; onSettled invalidates the affected queries whatever happened. Together they make optimistic updates safe.
Related terms
- optimistic update — Showing the result of a user’s action on screen immediately, before the server confirms it, and undoing it if the server says no.
- TanStack Query — A library that fetches, caches and refreshes server data in frontend apps, and runs changes to it as mutations.
- cache invalidation — Marking cached copies as out of date, or deleting them, when the real data changes so the next read fetches fresh data.
Taught in
- Optimistic UI Architecture: Cache & Rollback Protocols — Production Full-Stack Engineering