What problem does it solve?
This Skill solves the problem of inconsistent or hard-to-debug Zustand store behavior by standardizing how actions, dispatch reducers, optimistic updates, and slice composition should be implemented in LobeHub.
Core Features & Use Cases
- Action hierarchy: Separate UI-facing public actions, internal business actions (prefixed with internal_), and state update dispatchers (internal_dispatch*), so intent is clear and responsibilities stay isolated.
- Optimistic update pattern: Apply immediate UI updates for create/update flows (including temp IDs) while reconciling with backend services for consistency.
- Reducer vs set guidance: Use reducer-style updates for maps/lists such as messagesMap/topicMaps and use direct set updates for simple primitives to reduce complexity and stale state issues.
- Class-based slice actions: Migrate slices from plain StateCreator objects to class-based action implementations with private fields and typed public method exposure via Pick, then compose them correctly using flattenActions.
- Composition & selectors: Integrate multiple action classes into one store slice using flattenActions, and structure state access through maps, selectors, and well-defined store augmentation types.
Use Case Example: Build a chat topic flow where creating a topic updates topicMaps optimistically, calls the backend, and refreshes messages/topics to prevent stale reads across useChatStore/useUserStore/useGlobalStore.
Quick Start
Use the zustand Skill conventions to implement a new slice under src/store/** by defining a public/internal/dispatch action flow, applying optimistic updates where safe, and composing class-based slices via flattenActions.