zustand

Implements LobeHub Zustand store conventions for slices, actions, and optimistic updates.

Updated Aug 15, 2025
One-click install
npx skills add https://github.com/yehezkieldio/topaz --skill zustand-yehezkieldio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zustand
Source: https://github.com/yehezkieldio/topaz/tree/main/.agents/skills/zustand
Command: npx skills add https://github.com/yehezkieldio/topaz --skill zustand-yehezkieldio

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? It standardizes how Zustand stores are structured in the LobeHub codebase, preventing inconsistent action naming, scattered slice organization, and incorrect optimistic update patterns when editing src/store code. ## Core Features & Use Cases - Action Type Hierarchy: Enforces the three-layer pattern of public actions, internal_* actions, and internal_dispatch* methods with clear responsibilities. - Optimistic Update Patterns: Provides proven create/update/delete flows with temporary IDs, reducer dispatches, and SWR cache refresh, including the rule that deletes skip optimistic updates. - Class-Based Slice Migration: Guides migration from plain StateCreator objects to class-based actions composed with flattenActions, including multi-class slices and store-access typing. - Use Case: When adding a new chat slice, follow the references to structure initialState, selectors, reducers, and actions consistently with existing slices like message and topic. ## Quick Start Ask the AI to refactor a Zustand store slice in src/store to follow the LobeHub action hierarchy and class-based action pattern.

Frequently Asked Questions about zustand

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

FAQPage Schema
How do I structure Zustand actions in a large store?

Split actions into three layers: public actions for UI calls, internal_* actions for business logic and service calls, and internal_dispatch* methods for reducer-based state updates. UI components should only call public actions.

How to implement optimistic updates in Zustand?

Dispatch a temporary state change immediately with a generated temp ID, call the backend service, then refresh from the server for consistency. Delete operations should skip optimistic updates because recovery is complex.

When should I use a reducer versus simple set in Zustand?

Use the reducer pattern for object lists or maps, optimistic updates, and complex state transitions. Use simple set for toggling booleans, updating single values, or setting individual state fields.

How do I migrate Zustand slices to class-based actions?

Define a class receiving (set, get, api) in its constructor with #private fields, then compose instances in the store using flattenActions instead of spreading. Export a Pick type to expose only public methods.

How should Zustand slice files be organized?

Each slice directory contains initialState.ts, action.ts, selectors.ts, and optionally reducer.ts. Aggregate slices in the store's initialState.ts and store.ts, and export selectors through an xxxSelectors object.