zustand-state

Optimize Zustand store selectors, middleware, and slice architecture.

11|2|Updated Feb 5, 2026
One-click install
npx skills add https://github.com/recca0120/code-quest --skill zustand-state-recca0120
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zustand-state
Source: https://github.com/recca0120/code-quest/tree/main/.claude/skills/zustand-state
Command: npx skills add https://github.com/recca0120/code-quest --skill zustand-state-recca0120

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Zustand stores can become slow and hard to maintain when selectors are broad, middleware order is wrong, or realtime events are wired inside React components.

Core Features & Use Cases

  • Store architecture that scales: create shared root stores, compose slices for large state, and keep store initialization predictable.
  • Re-render optimization: select only the minimal state shape, use shallow selectors where appropriate, and avoid identity churn.
  • Middleware + async + realtime patterns: apply middleware in the correct stack order, keep async logic inside actions, and sync socket events to the store outside React.

Quick Start

Use zustand-state when you are implementing or refactoring a Zustand store and need reliable selectors, slice composition, and safe socket-to-store updates for a real-time UI.

Frequently Asked Questions about zustand-state

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

FAQPage Schema
How do I prevent excessive re-renders when using Zustand selectors in React?

To prevent excessive re-renders with Zustand selectors, select only the minimal state shape needed and apply useShallow for shallow comparisons. Using atomic selectors prevents identity churn and ensures components only re-render when their specific state slice updates.

What is the correct order to stack Zustand middleware for async actions?

Correct Zustand middleware stacking order is crucial for predictable store initialization. Apply middleware in the proper sequence so that async logic remains encapsulated inside store actions, ensuring middleware composition executes reliably before state updates occur.

How do I sync Socket.IO events to a Zustand store outside React components?

To sync Socket.IO or WebSocket events to a Zustand store outside React, attach event listeners directly to the store using getState and setState. This keeps realtime updates decoupled from component lifecycles and prevents fragile store wiring.

Can I use Zustand createStore for non-React modules that need optimized state subscriptions?

Yes, you can use Zustand createStore for non-React modules requiring optimized state subscriptions. The create hook is for React components, while createStore allows vanilla JavaScript modules to access state directly via getState and setState calls.

How do I test Zustand stores with direct getState and setState calls?

Testing Zustand stores via direct getState and setState calls bypasses React rendering complexities. This approach allows you to assert state transitions and middleware behavior in isolation by manipulating and verifying the store synchronously.

When should I compose Zustand slices for large state architecture?

Compose Zustand slices for large state architecture when managing scalable applications. Slice-based architecture allows you to split complex state into manageable segments, keeping shared root store initialization predictable and preventing monolithic store wiring.