कंटेंट पर जाएँ
TakoAPI
स्किल्स पर वापस

cart-management

konscious0beast द्वारा

Web & Frontend Development
325clawskills.sh द्वारा बताए गए डाउनलोड
0व्यूज़
0 लाइकइस स्किल को लाइक करने के लिए साइन इन करें
—अभी तक कोई रेटिंग नहीं
आपकी रेटिंग

संक्षिप्त

React cart state management: duplicate prevention, localStorage persistence, CartContext patterns.

विवरण

यह स्किल क्या करती है

Patterns for managing shopping cart state in React apps. Covers duplicate prevention, localStorage persistence, and CartContext design. Centralizes cart logic to avoid scattered state across components.

Centralizing cart logic in a context prevents the duplicate-state bugs that arise when multiple components each manage their own cart slice.

इसे कब इस्तेमाल करें

  • Preventing duplicate products when user clicks Add to Cart twice
  • Persisting cart contents after page refresh
  • Syncing cart state across multiple tabs
  • Updating item quantities without creating duplicate entries
  • Centralizing cart logic away from individual product components

उदाहरण वर्कफ़्लो

इनपुट

User asks: How do I add a product to the cart without allowing duplicates, and make it persist on refresh?

एजेंट
  1. 1

    Create a CartContext with cartItems and productIdsInCart state

  2. 2

    Initialize cartItems from localStorage on mount

  3. 3

    Implement addToCart that checks productIdsInCart.includes(item.id) before adding

  4. 4

    On each add, update both state arrays and write to localStorage

  5. 5

    Provide the context via CartProvider wrapping the app

आउटपुट

A CartContext where duplicate adds are silently ignored, cart survives refresh, and all product components consume a single source of truth.

इंस्टॉलेशन

clawhub install konscious0beast/cart-management

CLI कमांड चलाएँ, या प्रॉम्प्ट को Claude Code, Cursor, Codex या जो भी कोडिंग एजेंट आप इस्तेमाल करते हैं उसमें पेस्ट करें।

लिंक