← 返回 Skills 市场
konscious0beast

Cart Management

作者 konscious0beast · GitHub ↗ · v1.0.0
cross-platform ✓ 安全检测通过
540
总下载
0
收藏
2
当前安装
1
版本数
在 OpenClaw 中安装
/install cart-management
功能描述
React cart state management: duplicate prevention, localStorage persistence, CartContext patterns. Use when building or fixing shopping carts, product lists,...
使用说明 (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.

安全使用建议
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.
功能分析
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.
能力评估
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.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install cart-management
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /cart-management 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
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.
元数据
Slug cart-management
版本 1.0.0
许可证
累计安装 3
当前安装数 2
历史版本数 1
常见问题

Cart Management 是什么?

React cart state management: duplicate prevention, localStorage persistence, CartContext patterns. Use when building or fixing shopping carts, product lists,... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 540 次。

如何安装 Cart Management?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install cart-management」即可一键安装,无需额外配置。

Cart Management 是免费的吗?

是的,Cart Management 完全免费(开源免费),可自由下载、安装和使用。

Cart Management 支持哪些平台?

Cart Management 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Cart Management?

由 konscious0beast(@konscious0beast)开发并维护,当前版本 v1.0.0。

💬 留言讨论