0
Challenge · 98React 19 Frontier

useOptimistic

React 19used in ~20% of apps

Hand-rolled optimistic UI means manually snapshotting the old value and writing a rollback in every catch block — easy to forget, easy to get wrong. useOptimistic does the snapshot-and-revert for you: you describe the optimistic value, run your async Action, and React shows the guess while it's pending and snaps back automatically if it fails.

Core idea. useOptimistic(realValue, reducer) returns an optimistic value that equals realValue normally, but shows the reducer's result while an Action is pending — then automatically falls back to realValue when the Action settles, so success persists and failure reverts with no manual rollback.
Playground, this isn't a screenshot
<Thread />in sync
Shipped the feed
Optimistic next

Hit send: the message shows instantlyas "sending…" while the Action runs. On success it settles into the real thread; with server will fail on, the Action throws and React auto-reverts the optimistic bubble — you never wrote the rollback.

↑ play a little first, then dig in