cart-management

React cart state management: duplicate prevention, localStorage persistence, CartContext patterns. Use when building or fixing shopping carts, product lists, or cart-related UI.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "cart-management" with this command: npx skills add konscious0beast/cart-management

Cart Management Skill

Patterns for React cart state: duplicate prevention, persistence, context design.

Duplicate Prevention

  • Track product IDs in CartContext (separate state or derived from cartItems)
  • Check productIdsInCart.includes(item.id) before add
  • Centralize logic in context, not in ProductCard or child components

Persistence (localStorage)

  • Initialize cart state from localStorage.getItem('cart') on mount
  • Persist on every add/remove: localStorage.setItem('cart', JSON.stringify(cartItems))
  • Sync productIdsInCart if used: localStorage.setItem('cart_ids', JSON.stringify(ids))
  • Prevents duplicates across sessions (refresh, new tab)

CartContext Pattern

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]));
  }
};

Anti-Patterns

  • Don't add to cart in useEffect on ProductCard mount (causes duplicates)
  • Don't duplicate logic in multiple components – use context
  • Add backend validation as fallback for data integrity

Quantity Updates

For same-product quantity: use cartItems.map() to update item.quantity, don't create duplicate entries.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Session-Memory Enhanced

Session-Memory Enhanced v4.0 - 统一增强版。融合 session-memory + memu-engine 核心功能。特性:结构化提取 + 向量检索 + 不可变分片 + 三位一体自动化 + 多代理隔离 + AI 摘要 + 零配置启动。

Registry SourceRecently Updated
General

PRISM-GEN-DEMO

English: Retrieve, filter, sort, merge, and visualize multiple CSV result files from PRISM-Gen molecular generation/screening. Provides portable query-based...

Registry SourceRecently Updated
General

Video Pro by cza999

专业AI视频生成器,支持文本转高质量短视频,批量处理、多模板和高级自定义语音功能,适合创作者和企业。

Registry SourceRecently Updated
0133
cza999