Skip to main content

useOptimisticCart

The useOptimisticCart takes an existing cart object, processes all pending cart actions, and locally mutates the cart with optimistic state. An optimistic cart makes cart actions immediately render in the browser while actions sync to the server. This increases the perceived performance of the application.

The cart object from context.cart.get() returned by a server loader.

< = { lines?: { nodes: Array<{id: string; quantity: number; merchandise: {is: string}}>; }; }>

A new cart object augmented with optimistic state for lines and totalQuantity. Each cart line item that is optimistically added includes an isOptimistic property. Also if the cart has any optimistic state, a root property isOptimistic will be set to true.



Was this page helpful?