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.

In more detail

The TanStack Query recipe has four steps: cancel in-flight queries for that data, snapshot the current cache, write the optimistic change, and on error restore the snapshot. Finally, invalidate the query when the mutation settles so the screen matches the server.

Example

In React 19, useOptimistic keeps the optimistic value only while the Action is pending and falls back to the real state when it finishes or fails.

Related terms

Taught in

References