Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
Show the optimistic state immediately with useOptimistic inside an action, let React revert it when the action ends, and on failure show an error and reconcile with the server's real state.
useOptimistic returns a temporary value derived from the real state plus pending changes. Inside a transition or form action you call addOptimistic, then await the server mutation; when the action finishes, React drops the optimistic value and renders the real state, which you update from the server's response. On failure, the optimistic value disappears automatically, and you show an error rather than silently leaving the UI wrong. Disable or queue repeated clicks if the server cannot handle reordered requests, prefer idempotent requests such as 'set liked to true' over 'toggle', and revalidate the data so counts reflect other users' actions.