Cart actions overview
Summary of the cart mutation helpers exposed by use-shopping-cart.
Each cart action is a focused helper that mutates the client-side cart state and keeps the UI in sync. Use this overview to decide which helper you need, then drill into the detailed reference pages that follow.
State mutation helpers
addItem(product)— Insert a new product or merge quantities when the item already exists.incrementItem(id, opts?)— Increase a line item’s quantity by one (or a custom step) while preserving product metadata.decrementItem(id, opts?)— Decrease quantity and remove the line once the count hits zero.setItemQuantity(id, quantity)— Directly set an absolute quantity when you have a numeric input field.removeItem(id)— Drop a product completely without touching the rest of the cart.clearCart()— Reset the cart state, useful after a successful checkout or when signing a user out.
Session + Checkout helpers
loadCart(cartDetails, shouldMerge?)— Replace or merge the cart with cart entries from elsewhere, for example a logged-in user's saved cart.redirectToCheckout(sessionUrl)— send the browser to the Stripe Checkout Session URL your server created (a standalone function, not a cart method).
UI feedback helpers
handleCartClick()— ToggleshouldDisplayCart, for a cart button that opens and closes the cart.handleCartHover()— SetshouldDisplayCarttotrue, for opening the cart on hover.handleCloseCart()— SetshouldDisplayCarttofalse, for close buttons and backdrops.storeLastClicked(id)— Save a product ID aslastClicked, for example to highlight the product a customer last interacted with.
