Examples · Data & cache
Optimistic mutation
Write the UI first, send later, roll back on failure.
The button feels instant because optimistic runs before the request. The mutation snapshots the listed resources first; if the server fails, only this change is rolled back, concurrent edits survive.
What to notice
like.pendingdisables the button: a double-submit guard for free.- The mock server fails every third POST; the count jumps back and the error is shown.
- Rollback is a patch log, not a snapshot restore: other optimistic edits in flight stay applied.
Click three times quickly and watch the third one roll back.