Agent skill
managing-global-state
Defines when and how to manage shared state using React Context or Zustand. Use for global persistent data like the "Booking Cart".
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/managing-global-state
SKILL.md
Global State Management
When to use this skill
- Managing a "Booking Cart" or "Wishlist".
- Storing temporary user preferences during a session.
- Avoid prop-drilling more than 3 levels deep.
Tools
- Zustand: Preferred for its simplicity and performance in Next.js.
- React Context: Use for simple theme or auth state.
Implementation (Zustand)
import { create } from 'zustand';
import { Tour } from '@/types';
interface CartState {
items: Tour[];
addItem: (tour: Tour) => void;
removeItem: (id: string) => void;
clearCart: () => void;
}
export const useCartStore = create<CartState>((set) => ({
items: [],
addItem: (tour) => set((state) => ({ items: [...state.items, tour] })),
removeItem: (id) => set((state) => ({ items: state.items.filter(i => i.$id !== id) })),
clearCart: () => set({ items: [] }),
}));
Instructions
- Persistence: Use Zustand's middleware for
localStorageif the cart needs to survive refresh. - Context Boundaries: Keep Context Providers high up in
layout.tsx.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?