mutation

A change to data, and in TanStack Query or tRPC specifically, a request that creates, updates or deletes data on the server.

In more detail

Queries only read, while mutations write, so mutations are where caches must be invalidated and CSRF tokens checked. The TanStack Query mutation lifecycle is also the place to apply and roll back optimistic updates.

Examples

React cannot see mutations of state or props, so nothing re-renders; refs are the deliberate exception, a mutable box React does not track.
With TanStack Query, a mutation means a request that changes data on the server.
props.items.slice().sort() // copy first, then sort

Related terms

Taught in

References