スキル zustand-store-ts
📦

zustand-store-ts

安全

Build Type-Safe Zustand Stores for React

Managing React state with proper TypeScript types and middleware is complex. This skill provides proven patterns for creating maintainable Zustand stores with subscribeWithSelector and clear state/action separation.

対応: Claude Codex Code(CC)
🥉 75 ブロンズ
1

スキルZIPをダウンロード

2

Claudeでアップロード

設定 → 機能 → スキル → スキルをアップロードへ移動

3

オンにして利用開始

テストする

「zustand-store-ts」を使用しています。 Create a counter store with increment, decrement, and reset actions

期待される結果:

A TypeScript store interface with count state and three action methods, plus the create() implementation with subscribeWithSelector middleware wrapped around the store definition.

「zustand-store-ts」を使用しています。 How do I subscribe to only the userId change?

期待される結果:

Use store.subscribe((state) => state.userId, (id) => console.log(id)) to receive callbacks only when userId changes, avoiding unnecessary executions for other state updates.

セキュリティ監査

安全
v1 • 2/25/2026

Static analysis flagged 19 patterns (14 external_commands, 5 blocker/crypto), but all are false positives. The backticks detected are markdown code fence delimiters for TypeScript examples, not shell execution. The cryptographic warnings reference 'subscribeWithSelector' text patterns, not actual crypto algorithms. This is a documentation-only skill with code examples for Zustand state management.

1
スキャンされたファイル
74
解析された行数
0
検出結果
1
総監査数
セキュリティ問題は見つかりませんでした
監査者: claude

品質スコア

38
アーキテクチャ
100
保守性
87
コンテンツ
50
コミュニティ
100
セキュリティ
100
仕様準拠

作れるもの

React Developer Building Global State

Create a new Zustand store for managing application-wide state like user sessions, themes, or feature flags with full TypeScript support.

Team Standardizing State Patterns

Establish consistent store patterns across a codebase with proper typing, middleware usage, and subscription best practices.

Migrating from Redux to Zustand

Convert existing Redux stores to lightweight Zustand stores while maintaining TypeScript types and optimizing re-renders.

これらのプロンプトを試す

Basic Store Creation
Create a Zustand store template for a shopping cart with items array and total price calculation. Use TypeScript and include the subscribeWithSelector middleware.
Store with Async Actions
Generate a user store with async login and logout actions. Include proper TypeScript interfaces for state and actions, with loading and error states.
Complex Store with Selectors
Create a project management store with tasks, filters, and computed selectors. Show how to use individual selectors to prevent unnecessary re-renders.
Non-React Subscription
Show how to subscribe to store changes outside React components for logging or integration with external systems like analytics.

ベストプラクティス

  • Always wrap stores with subscribeWithSelector middleware for granular subscriptions
  • Define separate interfaces for state and actions, then combine them for the store type
  • Use selector functions in components to subscribe only to needed state slices

回避

  • Destructuring the entire store in components causes re-renders on any state change
  • Creating stores without TypeScript interfaces loses type safety benefits
  • Subscribing to the entire state object when only one property is needed

よくある質問

Why use subscribeWithSelector instead of the default middleware?
subscribeWithSelector enables granular subscriptions that only trigger when specific state properties change, improving performance by avoiding unnecessary re-renders and callback executions.
Should I create one store or multiple stores?
Start with separate stores for unrelated domains (user, cart, settings). Combine related state in a single store when actions frequently update multiple properties together.
How do I handle async actions in Zustand?
Define async functions in your actions interface. Inside the implementation, use async/await syntax and call set() with the updated state after the async operation completes.
Can I use Zustand stores outside React components?
Yes, stores can be imported and used anywhere. Use the subscribe method to listen for changes in non-React code, such as utilities, services, or analytics integrations.
What is the difference between get() and direct state access?
get() provides the current store state inside actions without subscribing to updates. It is useful for accessing fresh state values during action execution without triggering re-renders.
Do I need to clean up subscriptions manually?
Yes, store.subscribe returns an unsubscribe function. Call it when the subscription is no longer needed, such as in useEffect cleanup or when destroying external listeners.

開発者の詳細

ファイル構成

📄 SKILL.md