Optimistic UI Updates for Form Submissions
Learn how to update the UI immediately on a user action before the server confirms success, and roll back if it fails.
Optimistic updates immediately reflect the expected result of a user's action in the UI — like showing a new comment right after submission — without waiting for the server's response to confirm it succeeded, making the app feel instantaneous. If the server later reports failure, the UI rolls back to its previous state and typically surfaces an error message explaining what happened.
An optimistic update is like a restaurant server bringing your appetizer to the table the moment you order, trusting the kitchen will confirm it shortly after — almost always correct, but if the kitchen turns out to be out of that dish, the server has to come back and take the plate away and apologize, rather than making you wait at the table until the kitchen confirms availability before bringing anything out at all.