Optimistic update
An optimistic update changes local application state immediately before the server confirms the operation. It makes interactions feel faster, but the application must handle failures and preserve enough information to recover safely.
Minimal example
const result = useCart.getState().add(5, line);
if (result !== "ok") {
throw new Error("Cart belongs to another restaurant");
}Learn this concept
Lesson 4.19 · Resilient client patternsUsed in exercises
Exercise 4.21 · Cart synchronization helperPrerequisite conceptsZustand