React Best Practices

Chapter 5 · Practice 4 of 5

Show instant feedback with useOptimistic

From Forms and actions in React 19

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 UIWait for the server instead
Liking a postPayments
Adding a message to a chatDeletions
Small, easily undone changesAnything 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