zustand-patterns

Create typed, modular Zustand stores for React applications with Slice and middleware patterns.

1|Updated Apr 13, 2026
One-click install
npx skills add https://github.com/Inteligentsensingsolutions/tdd-dev-workflow --skill zustand-patterns-inteligentsensingsolutions
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zustand-patterns
Source: https://github.com/Inteligentsensingsolutions/tdd-dev-workflow/tree/main/skills/zustand-patterns
Command: npx skills add https://github.com/Inteligentsensingsolutions/tdd-dev-workflow --skill zustand-patterns-inteligentsensingsolutions

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Zustand stores in React apps often become untyped, trigger unnecessary re-renders, and are difficult to compose, persist, and test; this Skill provides patterns and conventions to design maintainable, performant, and well-typed client-side stores.

Core Features & Use Cases

  • Clear typing separation: separate State and Actions interfaces to improve DX and composability in TypeScript projects.
  • Selective subscriptions: enforce subscribeWithSelector and individual selectors to minimize re-renders and enable outside-React listeners.
  • Middleware composition: recommended ordering and use of devtools, persist, subscribeWithSelector, and immer for debugging, hydration, and safe nested updates.
  • Slice pattern & cross-slice actions: split large stores into focused slices for auth, cart, preferences, and coordinate actions across slices.
  • Hydration & testing: handle asynchronous persist hydration, provide reset actions for test isolation, and patterns for asserting store behavior in unit tests.
  • Performance patterns: derived selectors, transient updates without re-render, and using shallow/selectors for composite reads.

Quick Start

Create a typed Zustand store using subscribeWithSelector, split into auth and cart slices, and add persist and immer middleware to enable hydration and safe nested updates.

Frequently Asked Questions about zustand-patterns

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

FAQPage Schema
How do I prevent unnecessary re-renders in React using Zustand?

To prevent unnecessary re-renders in Zustand, enforce subscribeWithSelector and use individual selectors to ensure components only subscribe to specific state slices. This minimizes updates and enables outside-React listeners for optimized performance.

What is the best way to structure a typed Zustand store in TypeScript?

The best way to structure a typed Zustand store is to separate State and Actions interfaces. This improves developer experience and composability by clearly defining data shapes and mutation functions within TypeScript projects.

How do I compose Zustand middleware for persistence and debugging?

Compose Zustand middleware by applying devtools, persist, subscribeWithSelector, and immer in a recommended order. This enables debugging, handles asynchronous hydration, and ensures safe nested state updates.

Can I split large Zustand stores into smaller focused slices?

Yes, you can split large Zustand stores into focused slices for auth, cart, and preferences. This slice pattern coordinates cross-slice actions and maintains performant, typed client-side state management.

How do I handle asynchronous persist hydration and testing in Zustand?

Handle asynchronous persist hydration by applying the persist middleware and providing reset actions. This ensures test isolation and establishes patterns for asserting store behavior in unit tests.