zustand

Organize Zustand stores with slices, reducers, selectors, and flattened actions.

Updated Dec 12, 2024
One-click install
npx skills add https://github.com/kingmacth/lobe-chat --skill zustand-kingmacth
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zustand
Source: https://github.com/kingmacth/lobe-chat/tree/main/.agents/skills/zustand
Command: npx skills add https://github.com/kingmacth/lobe-chat --skill zustand-kingmacth

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Zustand provides a compact, scalable approach to managing React app state using stores, slices, and selectors, reducing prop drilling and boilerplate while enabling organized action flows.

Core Features & Use Cases

  • Structured action patterns: public actions, internal actions, and dispatch methods to coordinate complex state changes.
  • Reducer vs set: guidance on when to use reducers for complex state transitions or simple set for toggles.
  • Class-based action composition: patterns for encapsulating actions with typed stores and flattening actions for ergonomics.

Quick Start

Create a Zustand store slice following the slice-organization patterns, wire it into components, and adopt the action patterns described.

Frequently Asked Questions about zustand

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a scalable Zustand store in React?

Structure a scalable Zustand store using slice-based architectures to organize state, reducers, and selectors. Define TypeScript interfaces and class-based action patterns to flatten actions, reducing boilerplate while coordinating complex state transitions across diverse UI patterns.

When should I use reducers instead of set for Zustand state management?

Use reducers for Zustand state management when handling complex state transitions requiring structured logic, and use simple set methods for straightforward toggles. This guidance ensures organized action flows and prevents bloated update logic within your React store slices.

What is the best way to organize public and internal actions in a Zustand store?

Organize Zustand actions using class-based action composition to encapsulate typed stores and flatten actions for ergonomics. Separate public actions for external component calls from internal actions and dispatch methods to coordinate complex state changes cleanly.

How do I use TypeScript interfaces with Zustand slices and selectors?

Define TypeScript interfaces to enforce strict typing across Zustand slices and selectors. This requires typing the store state, class-based action patterns, and flattened actions, ensuring scalable state management and type-safe component integration in React applications.

Does Zustand state management work for complex React stores with diverse UI patterns?

Zustand state management works for complex React stores by applying slice-based architectures and selector usage across diverse UI patterns. It reduces prop drilling and boilerplate while enabling organized action flows for scalable applications.