zustand — how to use zustand how to use zustand, zustand state management, zustand vs mobx, zustand install guide, what is zustand, zustand alternative, zustand setup tutorial, zustand action type hierarchy, zustand public actions, zustand internal actions

v1.0.0
GitHub

About this Skill

Ideal for Frontend Agents requiring efficient state management for complex UI component interactions. zustand is a state management system that utilizes an Action Type Hierarchy, comprising public actions, internal actions, and dispatch methods to manage application state.

Features

Utilizes a hierarchical Action Type structure for organized state management
Supports public actions for UI component interactions with verb form naming conventions
Employs internal actions with an `internal_` prefix for core business logic implementation
Enables optimistic updates and service calls through internal actions
Provides dispatch methods for efficient state updates

# Core Topics

lildibbb lildibbb
[0]
[0]
Updated: 2/24/2026

Quality Score

Top 5%
57
Excellent
Based on code quality & docs
Installation
SYS Universal Install (Auto-Detect)
Cursor IDE Windsurf IDE VS Code IDE
> npx killer-skills add lildibbb/tele-crm-frontend/zustand

Agent Capability Analysis

The zustand MCP Server by lildibbb is an open-source Categories.community integration for Claude and other AI agents, enabling seamless task automation and capability expansion. Optimized for how to use zustand, zustand state management, zustand vs mobx.

Ideal Agent Persona

Ideal for Frontend Agents requiring efficient state management for complex UI component interactions.

Core Value

Empowers agents to manage hierarchical state structures with optimistic updates, parameter validation, and flow orchestration using Zustand's action type hierarchy, including public actions, internal actions, and dispatch methods.

Capabilities Granted for zustand MCP Server

Orchestrating UI component interactions with public actions like createTopic and sendMessage
Implementing core business logic with internal actions like internal_createTopic
Dispatching actions with optimistic updates and error handling

! Prerequisites & Limits

  • Requires understanding of Zustand's action type hierarchy
  • Limited to state management use cases
  • May require additional setup for complex UI component interactions
Project
SKILL.md
4.8 KB
.cursorrules
1.2 KB
package.json
240 B
Ready
UTF-8

# Tags

[No tags]
SKILL.md
Readonly

LobeHub Zustand State Management

Action Type Hierarchy

1. Public Actions

Main interfaces for UI components:

  • Naming: Verb form (createTopic, sendMessage)
  • Responsibilities: Parameter validation, flow orchestration

2. Internal Actions (internal_*)

Core business logic implementation:

  • Naming: internal_ prefix (internal_createTopic)
  • Responsibilities: Optimistic updates, service calls, error handling
  • Should not be called directly by UI

3. Dispatch Methods (internal_dispatch*)

State update handlers:

  • Naming: internal_dispatch + entity (internal_dispatchTopic)
  • Responsibilities: Calling reducers, updating store

When to Use Reducer vs Simple set

Use Reducer Pattern:

  • Managing object lists/maps (messagesMap, topicMaps)
  • Optimistic updates
  • Complex state transitions

Use Simple set:

  • Toggling booleans
  • Updating simple values
  • Setting single state fields

Optimistic Update Pattern

typescript
1internal_createTopic: async (params) => { 2 const tmpId = Date.now().toString(); 3 4 // 1. Immediately update frontend (optimistic) 5 get().internal_dispatchTopic( 6 { type: 'addTopic', value: { ...params, id: tmpId } }, 7 'internal_createTopic' 8 ); 9 10 // 2. Call backend service 11 const topicId = await topicService.createTopic(params); 12 13 // 3. Refresh for consistency 14 await get().refreshTopic(); 15 return topicId; 16},

Delete operations: Don't use optimistic updates (destructive, complex recovery)

Naming Conventions

Actions:

  • Public: createTopic, sendMessage
  • Internal: internal_createTopic, internal_updateMessageContent
  • Dispatch: internal_dispatchTopic
  • Toggle: internal_toggleMessageLoading

State:

  • ID arrays: messageLoadingIds, topicEditingIds
  • Maps: topicMaps, messagesMap
  • Active: activeTopicId
  • Init flags: topicsInit

Detailed Guides

  • Action patterns: references/action-patterns.md
  • Slice organization: references/slice-organization.md

Class-Based Action Implementation

We are migrating slices from plain StateCreator objects to class-based actions.

Pattern

  • Define a class that encapsulates actions and receives (set, get, api) in the constructor.
  • Use #private fields (e.g., #set, #get) to avoid leaking internals.
  • Prefer shared typing helpers:
    • StoreSetter<T> from @/store/types for set.
    • Pick<ActionImpl, keyof ActionImpl> to expose only public methods.
  • Export a create*Slice helper that returns a class instance.
ts
1type Setter = StoreSetter<HomeStore>; 2export const createRecentSlice = (set: Setter, get: () => HomeStore, _api?: unknown) => 3 new RecentActionImpl(set, get, _api); 4 5export class RecentActionImpl { 6 readonly #get: () => HomeStore; 7 readonly #set: Setter; 8 9 constructor(set: Setter, get: () => HomeStore, _api?: unknown) { 10 void _api; 11 this.#set = set; 12 this.#get = get; 13 } 14 15 useFetchRecentTopics = () => { 16 // ... 17 }; 18} 19 20export type RecentAction = Pick<RecentActionImpl, keyof RecentActionImpl>;

Composition

  • In store files, merge class instances with flattenActions (do not spread class instances).
  • flattenActions binds methods to the original class instance and supports prototype methods and class fields.
ts
1const createStore: StateCreator<HomeStore, [['zustand/devtools', never]]> = (...params) => ({ 2 ...initialState, 3 ...flattenActions<HomeStoreAction>([ 4 createRecentSlice(...params), 5 createHomeInputSlice(...params), 6 ]), 7});

Multi-Class Slices

  • For large slices that need multiple action classes, compose them in the slice entry using flattenActions.
  • Use a local PublicActions<T> helper if you need to combine multiple classes and hide private fields.
ts
1type PublicActions<T> = { [K in keyof T]: T[K] }; 2 3export type ChatGroupAction = PublicActions< 4 ChatGroupInternalAction & ChatGroupLifecycleAction & ChatGroupMemberAction & ChatGroupCurdAction 5>; 6 7export const chatGroupAction: StateCreator< 8 ChatGroupStore, 9 [['zustand/devtools', never]], 10 [], 11 ChatGroupAction 12> = (...params) => 13 flattenActions<ChatGroupAction>([ 14 new ChatGroupInternalAction(...params), 15 new ChatGroupLifecycleAction(...params), 16 new ChatGroupMemberAction(...params), 17 new ChatGroupCurdAction(...params), 18 ]);

Store-Access Types

  • For class methods that depend on actions in other classes, define explicit store augmentations:
    • ChatGroupStoreWithSwitchTopic for lifecycle switchTopic
    • ChatGroupStoreWithRefresh for member refresh
    • ChatGroupStoreWithInternal for curd internal_dispatchChatGroup

Do / Don't

  • Do: keep constructor signature aligned with StateCreator params (set, get, api).
  • Do: use #private to avoid set/get being exposed.
  • Do: use flattenActions instead of spreading class instances.
  • Don't: keep both old slice objects and class actions active at the same time.

Related Skills

Looking for an alternative to zustand or building a Categories.community AI Agent? Explore these related open-source MCP Servers.

View All

widget-generator

Logo of f
f

widget-generator is an open-source AI agent skill for creating widget plugins that are injected into prompt feeds on prompts.chat. It supports two rendering modes: standard prompt widgets using default PromptCard styling and custom render widgets built as full React components.

149.6k
0
Design

chat-sdk

Logo of lobehub
lobehub

chat-sdk is a unified TypeScript SDK for building chat bots across multiple platforms, providing a single interface for deploying bot logic.

73.0k
0
Communication

zustand

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication

data-fetching

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication