zustand-store-ts

Create Zustand stores with TypeScript types and subscribeWithSelector middleware.

Updated Aug 11, 2026
One-click install
npx skills add https://github.com/DucCuong159/Realtime-chatapp --skill zustand-store-ts-duccuong159
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zustand-store-ts
Source: https://github.com/DucCuong159/Realtime-chatapp/tree/main/.agent/skills/zustand-store-ts
Command: npx skills add https://github.com/DucCuong159/Realtime-chatapp --skill zustand-store-ts-duccuong159

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires zustand, and includes assets (resource) components.

What problem does it solve? Setting up Zustand state management in a TypeScript React project often leads to inconsistent patterns, missing type safety, and unnecessary component re-renders. This Skill enforces established conventions so every store follows the same typed, selector-based structure. ## Core Features & Use Cases - Typed Store Scaffolding: Separates State and Actions interfaces and combines them into a single store type for full TypeScript safety. - Middleware Enforcement: Always wraps stores with subscribeWithSelector, enabling fine-grained subscriptions outside React components. - Render Optimization Guidance: Promotes individual selectors over whole-store destructuring to prevent unnecessary re-renders. - Use Case: When adding a new feature to the chat app frontend, generate a properly typed store in src/frontend/src/store/, export it from the index barrel file, and add matching tests. ## Quick Start Ask the AI to create a new Zustand store for your feature following the project patterns, for example: create a Zustand store named Conversation with typed state and actions.

Frequently Asked Questions about zustand-store-ts

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

FAQPage Schema
How do I create a Zustand store with TypeScript?

Define separate State and Actions interfaces, combine them into one store type, and pass it to create<Store>() with the subscribeWithSelector middleware. This gives full type inference for state, actions, and selectors.

How to subscribe to Zustand state outside React components?

Use store.subscribe with a selector function, which requires the subscribeWithSelector middleware. Pass a selector like (state) => state.selectedId and a callback that runs whenever that slice changes.

Why does my Zustand component re-render on every state change?

Destructuring the whole store with useMyStore() subscribes to all state, causing re-renders on any change. Use individual selectors like useMyStore((state) => state.items) to subscribe only to the slices you need.

What middleware should I use with Zustand for selectors?

Use subscribeWithSelector from zustand/middleware. It enables selector-based subscriptions both inside components via hooks and outside React via store.subscribe, which the default store does not support.

When should I not use a Zustand store for state?

Avoid a global store for purely local, ephemeral UI state that no other component needs. Zustand suits shared client state; server data caching or single-component toggles are better handled by other means.