Skip to main content
skill

zustand-store-ts — Claude Code skill: typed Zustand stores

A skill that sets the pattern for Zustand stores in TypeScript: separate state and action types, subscribeWithSelector, individual selectors.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add microsoft/skills --skill zustand-store-ts -a claude-code
Open on GitHub

What zustand-store-ts does

The skill spells out how to write global Zustand stores in a React project. It ships a template at assets/template.ts with placeholders {{StoreName}} and {{description}} — a PascalCase store name and a short JSDoc line.

The rules are strict. Wrap the store in subscribeWithSelector from zustand/middleware every time. Describe state and actions as separate interfaces, then combine them into one store type. In components, pull values with individual selectors so a re-render happens only when that field changes, not on every store update. Outside React, subscribe through useMyStore.subscribe with a selector and a callback.

Integration is four steps: create the store under src/frontend/src/store/, export it from src/frontend/src/store/index.ts, add tests in src/frontend/src/store/*.test.ts. Those paths are fixed, so a project with a different folder layout needs them rewritten first — worth checking before you install.

What it helps with

  • set up a global Zustand store with consistent types
  • split state and actions into separate interfaces
  • subscribe to a single field outside a React component
  • cut extra re-renders with individual selectors
  • place store files and tests where the project expects them

Example prompts for the agent

  • create a Project store using the zustand-store-ts template
  • add a loadItems action and a subscription on selectedId
  • split the store state and actions into separate interfaces

How to install zustand-store-ts

1Skills CLI (Vercel)

npx skills add microsoft/skills --skill zustand-store-ts -a claude-code

2Manually: put the files in place

~/.claude/skills/zustand-store-ts/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/zustand-store-ts/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about zustand-store-ts

How do I install zustand-store-ts in Claude?

Run npx skills add microsoft/skills --skill zustand-store-ts -a claude-code. The skill file then lives at ~/.claude/skills/zustand-store-ts/SKILL.md.

What does zustand-store-ts do?

It gives you a template and rules for Zustand stores in TypeScript: the subscribeWithSelector middleware, separate state and action types, individual selectors, and subscriptions outside React.

Where does the skill put store files?

Following its steps, the store goes in src/frontend/src/store/, gets exported from src/frontend/src/store/index.ts, and tests land in src/frontend/src/store/*.test.ts.

Source text

SKILL.md · MIT
---
name: zustand-store-ts
description: Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state/action separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.
license: MIT
metadata:
  author: Microsoft
  version: "1.0.0"
---

# Zustand Store

Create Zustand stores following established patterns with proper TypeScript types and middleware.

## Quick Start

Copy the template from [assets/template.ts](assets/template.ts) and replace placeholders:
- `{{StoreName}}` → PascalCase store name (e.g., `Project`)
- `{{description}}` → Brief description for JSDoc

## Always Use subscribeWithSelector

```typescript
import { create } from 'zustand';
import { subscribeWithSelector } from 'zustand/middleware';

export const useMyStore = create<MyStore>()(
  subscribeWithSelector((set, get) => ({
    // state and actions
  }))
);
```

## Separate State and Actions

```typescript
export interface MyState {
  items: Item[];
  isLoading: boolean;
}

export interface MyActions {
  addItem: (item: Item) => void;
  loadItems: () => Promise<void>;
}

export type MyStore = MyState & MyActions;
```

## Use Individual Selectors

```typescript
// Good - only re-renders when `items` changes
const items = useMyStore((state) => state.items);

// Avoid - re-renders on any state change
const { items, isLoading } = useMyStore();
```

## Subscribe Outside React

```typescript
useMyStore.subscribe(
  (state) => state.selectedId,
  (selectedId) => console.log('Selected:', selectedId)
);
```

## Integration Steps

1. Create store in `src/frontend/src/store/`
2. Export from `src/frontend/src/store/index.ts`
3. Add tests in `src/frontend/src/store/*.test.ts`

© Microsoft · MIT · microsoft/skills

Similar skills

Everything for Frontend and UI →

From the same set64

The whole set →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor