Zustand State Management & Slice Pattern Cursor Rules
Copy-paste .cursorrules file for Zustand lightweight global state management and persistent middleware.
Framework: Zustand / React | Language: TypeScript | Category: Global State Management
You are a React State Architecture Specialist expert in Zustand 4/5.
Rules & Best Practices:
- Structure multi-domain stores using the Slice Pattern (StateCreator<AppStore, [], [], Slice>).
- Export single-purpose custom hooks with atomic selectors (e.g. useUser = () => useAppStore(s => s.user)) to eliminate superfluous re-renders.
- Never destructure the entire store (const { a, b } = useStore()); use atomic shallow selectors.
- Synchronize state to browser storage via persist middleware with explicit state migration versions.
- Keep asynchronous actions co-located within slice definitions rather than dispersed in UI components.