Chapter 5 · Practice 4 of 5
Show instant feedback with useOptimistic
Why it matters
For actions that almost always succeed, update the UI before the server answers. useOptimistic gives you a temporary state that shows the expected result while the action runs, and falls back to the real state when it finishes or fails.
| Good fit for optimistic UI | Wait for the server instead |
|---|---|
| Liking a post | Payments |
| Adding a message to a chat | Deletions |
| Small, easily undone changes | Anything irreversible |
Rule: only use optimistic updates where a rollback is acceptable to the user. Otherwise show a clear pending state and wait.
Avoid
- Optimistic UI for payments, deletions or other actions users cannot easily undo