Optimistic UI improves perceived performance by updating the interface immediately, so users feel the app is responsive even if the server takes time to respond.
If the server rejects the change, the app must undo the optimistic update and inform the user to avoid confusion.
The code updates the likes count immediately on click, showing the optimistic UI change before the server confirms.
Option B updates state immediately, then tries the server call, and reverts if it fails. Others either update after server or don't handle errors properly.
The error handler uses the 'items' value from closure, which may be outdated if multiple calls happen quickly, causing state to revert incorrectly.
