Install
openclaw skills install cart-managementReact cart state management: duplicate prevention, localStorage persistence, CartContext patterns. Use when building or fixing shopping carts, product lists, or cart-related UI.
openclaw skills install cart-managementPatterns for React cart state: duplicate prevention, persistence, context design.
productIdsInCart.includes(item.id) before addlocalStorage.getItem('cart') on mountlocalStorage.setItem('cart', JSON.stringify(cartItems))localStorage.setItem('cart_ids', JSON.stringify(ids))const addToCart = (item: CartItem) => {
if (!productIdsInCart.includes(item.id)) {
setCartItems(prev => [...prev, item]);
setProductIdsInCart(prev => [...prev, item.id]);
localStorage.setItem('cart', JSON.stringify([...cartItems, item]));
}
};
For same-product quantity: use cartItems.map() to update item.quantity, don't create duplicate entries.