← Back to Skills Marketplace
konscious0beast

Cart Management

by konscious0beast · GitHub ↗ · v1.0.0
cross-platform ✓ Security Clean
540
Downloads
0
Stars
2
Active Installs
1
Versions
Install in OpenClaw
/install cart-management
Description
React cart state management: duplicate prevention, localStorage persistence, CartContext patterns. Use when building or fixing shopping carts, product lists,...
README (SKILL.md)

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.

Usage Guidance
This skill appears to be what it says (React cart patterns) and has no unusual external requirements. Before using the suggested code: 1) Fix the stale-state bug — compute the new cart from the previous state and then persist that new value to localStorage (use functional updates and write the same new object to storage). 2) Avoid duplicating derived state (keep product IDs derived from cart items, or ensure both are updated atomically). 3) Guard localStorage usage for server-side rendering (check for window) and wrap JSON.parse in try/catch. 4) Remember localStorage is readable by any page script — do not store secrets or sensitive info there (XSS risk). 5) Consider debouncing or batching persistence to reduce writes and handle concurrent updates safely. These are implementation-quality and security-adjacent issues, not signs of malicious behavior.
Capability Analysis
Type: OpenClaw Skill Name: cart-management Version: 1.0.0 The skill bundle describes React cart state management patterns, including duplicate prevention, localStorage persistence, and CartContext usage. The `SKILL.md` content is purely instructional, providing code examples and best practices for web development. There are no prompt injection attempts, shell commands, network calls, file system access, or any other indicators of malicious intent or risky behavior for an AI agent to execute. The use of `localStorage` refers to client-side browser storage, not agent-side operations.
Capability Assessment
Purpose & Capability
The name/description (React cart management, duplicate prevention, localStorage persistence, CartContext patterns) matches the SKILL.md instructions. No unrelated binaries, env vars, or installers are requested.
Instruction Scope
Instructions stay within cart management scope, but contain practical issues: the example writes localStorage with [...cartItems, item] (not using the functional 'prev' value) which can cause stale-state/race bugs; it duplicates derived state (cart IDs) which can get out-of-sync; it doesn't mention guarding localStorage access for SSR (window may be undefined) or handling JSON.parse errors. Also no warning about localStorage being accessible to page scripts (XSS risk).
Install Mechanism
Instruction-only skill with no install spec or downloads. Low install risk — nothing will be written to disk by an installer.
Credentials
No credentials, env vars, or config paths are requested. Declared requirements are minimal and appropriate for the described client-side task.
Persistence & Privilege
always is false and the skill does not request persistent platform privileges or modify other skills. It only recommends using browser localStorage, which is appropriate for a client-side cart pattern but has the usual browser-storage tradeoffs.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install cart-management
  3. After installation, invoke the skill by name or use /cart-management
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Initial release: provides robust patterns for React cart state management. - Prevents duplicate cart entries using product ID tracking in CartContext. - Persists cart state and product IDs in localStorage for session durability. - Centralizes add/remove logic within CartContext for maintainability. - Includes clear anti-patterns and recommendations for quantity management. - Designed for reuse in shopping carts, product lists, or cart-related UIs.
Metadata
Slug cart-management
Version 1.0.0
License
All-time Installs 3
Active Installs 2
Total Versions 1
Frequently Asked Questions

What is Cart Management?

React cart state management: duplicate prevention, localStorage persistence, CartContext patterns. Use when building or fixing shopping carts, product lists,... It is an AI Agent Skill for Claude Code / OpenClaw, with 540 downloads so far.

How do I install Cart Management?

Run "/install cart-management" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Cart Management free?

Yes, Cart Management is completely free (open-source). You can download, install and use it at no cost.

Which platforms does Cart Management support?

Cart Management is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Cart Management?

It is built and maintained by konscious0beast (@konscious0beast); the current version is v1.0.0.

💬 Comments