Ever clicked a like button and watched it stall for a second while the server thinks about it? That tiny delay makes your app feel sluggish. React 19 ships useOptimistic to fix exactly that — the UI changes before the server responds, and snaps back automatically if something goes wrong.
Learn React's useOptimistic hook by building instant heart toggles. Click the heart, see it turn red immediately, and let React handle the server in the background. If the request fails, the heart reverts on its own — no manual rollback code.
Render two cards side by side: one labeled "Successful toggle" and another "Error toggle".
Both cards start with the heart in a neutral (not liked) state.
Clicking the heart on the successful toggle card must:










