NextPlayground

useOptimistic

The useOptimistic hook shows a temporary, optimistic version of state while an async action is in flight. Below, each message appears instantly in a pending style, then switches to its confirmed style once the (artificially slow, 1.5s) server action resolves. If the action failed, React would automatically roll back to the last confirmed state.

react.dev/reference/react/useOptimistic
  • No messages yet — send one below.
useOptimistic Demo