useOptimistic removed about 80 lines of state juggling from our comment box
We had a pending-items array, a reconciliation effect, and a bug where a failed request left a ghost item. All of that is now the hook plus a server action.
Written by
Lena Fischer
Front-end engineer on a design systems team. I maintain the token pipeline and the component library four product teams build on. Strong opinions about focus rings, colour contrast, and the fact that most "theming" problems are really naming problems. CSS is a real language and I will keep saying so.
3 Comments
Sign in to join the discussion
It replaces the optimistic state with whatever the action returns, so the reconciliation is 'throw away my guess when the truth arrives'. The trap is doing work in the optimistic reducer that the server does differently — if your guess and the server disagree about ordering, users see a jump on every send.
The ghost item left behind by a failed request is a bug I have now written in three different frameworks.