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

Taught in

References