secondsky/claude-skills / plugins/zustand-state-management/skills/zustand-state-management
zustand-state-management
VerifiedZustand state management for React with TypeScript. Use for global state, Redux/Context API migration, localStorage persistence, slices pattern, devtools, Next.js SSR, or encountering hydration errors, TypeScript inference issues, persist middleware problems, infinite render loops.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 9.7 KB |
| assets/example-template.txt | markdown | 416 B |
| references/advanced-topics.md | markdown | 7.9 KB |
| references/common-patterns.md | markdown | 6.4 KB |
| references/example-reference.md | markdown | 760 B |
| references/known-issues.md | markdown | 5.4 KB |
| references/middleware-guide.md | markdown | 5.2 KB |
| references/migration-guide.md | markdown | 6.2 KB |
| references/nextjs-hydration.md | markdown | 5.0 KB |
| references/typescript-patterns.md | markdown | 4.9 KB |
| scripts/check-versions.shexecutable | script | 3.6 KB |
| scripts/example-script.shexecutable | script | 302 B |
| templates/async-actions-store.ts | script | 7.6 KB |
| templates/basic-store.ts | script | 908 B |
| templates/computed-store.ts | script | 5.6 KB |
| templates/devtools-store.ts | script | 3.4 KB |
| templates/nextjs-store.ts | script | 2.6 KB |
| templates/persist-store.ts | script | 2.8 KB |
| templates/slices-pattern.ts | script | 5.0 KB |
| templates/typescript-store.ts | script | 1.8 KB |
templates/devtools-store.ts
View on GitHub/**
* Zustand Store with Redux DevTools Integration
*
* Use when:
* - Need debugging capabilities
* - Want to track state changes
* - Inspecting actions and state history
* - Time-travel debugging (with Redux DevTools Extension)
*
* Setup:
* 1. Install Redux DevTools Extension in browser
* 2. Use this template
* 3. Open DevTools → Redux tab
*
* Learn more: See SKILL.md for combining with other middleware
*/
import { create } from 'zustand'
import { devtools } from 'zustand/middleware'
interface Todo {
id: string
text: string
done: boolean
}
interface DevtoolsStore {
// State
todos: Todo[]
filter: 'all' | 'active' | 'completed'
// Actions
addTodo: (text: string) => void
toggleTodo: (id: string) => void
deleteTodo: (id: string) => void
setFilter: (filter: DevtoolsStore['filter']) => void
clearCompleted: () => void
}
export const useDevtoolsStore = create<DevtoolsStore>()(
devtools(
(set) => ({
// Initial state
todos: [],
filter: 'all',
// Actions with named actions for DevTools
addTodo: (text) =>
set(
(state) => ({
todos: [
...state.todos,
{ id: Date.now().toString(), text, done: false },
],
}),
undefined,
'todos/add', // Action name in DevTools
),
toggleTodo: (id) =>
set(
(state) => ({
todos: state.todos.map((todo) =>
todo.id === id ? { ...todo, done: !todo.done } : todo
),
}),
undefined,
'todos/toggle',
),
deleteTodo: (id) =>
set(
(state) => ({
todos: state.todos.filter((todo) => todo.id !== id),
}),
undefined,
'todos/delete',
),
setFilter: (filter) =>
set(
{ filter },
undefined,
'filter/set',
),
clearCompleted: () =>
set(
(state) => ({
todos: state.todos.filter((todo) => !todo.done),
}),
undefined,
'todos/clearCompleted',
),
}),
{
name: 'TodoStore', // Store name in DevTools
enabled: process.env.NODE_ENV === 'development', // Optional: only in dev
},
),
)
/**
* Usage in component:
*
* function TodoList() {
* const todos = useDevtoolsStore((state) => state.todos)
* const filter = useDevtoolsStore((state) => state.filter)
* const toggleTodo = useDevtoolsStore((state) => state.toggleTodo)
* const deleteTodo = useDevtoolsStore((state) => state.deleteTodo)
*
* const filteredTodos = todos.filter((todo) => {
* if (filter === 'active') return !todo.done
* if (filter === 'completed') return todo.done
* return true
* })
*
* return (
* <ul>
* {filteredTodos.map((todo) => (
* <li key={todo.id}>
* <input
* type="checkbox"
* checked={todo.done}
* onChange={() => toggleTodo(todo.id)}
* />
* <span>{todo.text}</span>
* <button onClick={() => deleteTodo(todo.id)}>Delete</button>
* </li>
* ))}
* </ul>
* )
* }
*
* DevTools Features:
* - See all actions in order
* - Inspect state before/after each action
* - Time-travel through state changes
* - Export/import state for debugging
* - Track which components caused updates
*/
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |