useOptimistic in React 19: The Rollback Is Free, the Draft Is Not
Every useOptimistic demo I have read increments something that cannot fail. A like counter. A todo that always saves. The optimistic update shows up, the server agrees, everyone goes home. That is the one case where you did not need the hook.
The reason optimistic UI is hard is the other case: you told the user it worked, and then the server said no. The note has to come off the list, the user has to find out why, and whatever they typed has to still be there so they can try again. That is the part this article is about.
So here is a form that can fail for real reasons. Aurora Coffee Co., the shop from React Server Components for SPA Veterans , lets customers leave brew notes on each coffee. A moderator can close the notes on a coffee at any moment, the network can drop, and the server can answer 500.…