useOptimistic: Instant UI Updates Before the Server Responds

Hands-on practice for this lecture. Work through the exercises and quizzes to reinforce what you've learned.

1

Exercise 1 of 1

useOptimistic Quiz

Three questions on React 19's useOptimistic β€” what it returns, what happens on server failure, and when optimistic UI is the right pattern.

1
const [optimisticMessages, addOptimisticMessage] = useOptimistic(
  messages,           // actual state from server
  (state, newMsg) => [...state, newMsg]
);

What does optimisticMessages contain?

2

What happens if the server action fails?

3

useOptimistic is most useful when…

0/3 answered

πŸ’‘ useOptimistic is React 19's primitive for optimistic UI. It pairs naturally with useActionState β€” the action runs, the optimistic state shows immediately, and React reconciles when the server responds.

Practice: useOptimistic: Instant UI Updates Before the Server Responds β€” Interactive Exercises | Durgesh Rai