If you've been working with Zustand for state management in React, you know how elegant and powerful it is. But what if you could make your Zustand development experience even better?
Today, I'm excited to announce Zustand Copilot β a VS Code extension designed to be the definitive toolkit for Zustand v5+ development.
π€ Why I Built This
After building dozens of React applications with Zustand, I found myself:
- π Typing the same store boilerplate over and over
- π Constantly switching to docs for syntax reference
- π Forgetting to use
useShallowfor multi-value selectors (hello, unnecessary re-renders!) - π Manually setting up the Slices Pattern for larger apps
Zustand Copilot solves all of these problems.
β¨ Key Features
1. TypeScript-First Snippets
Just type a prefix and get production-ready code:
| Prefix | What You Get |
|---|---|
zstore |
Complete store with devtools |
zslice |
Slice for the Slices Pattern |
zpersist |
Persisted store with localStorage |
zshallow |
useShallow selector (performance!) |
zasync |
Async store with loading states |
zimmer |
Immer-powered mutable updates |
Example: Type zstore and get:
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
interface CounterState {
count: number;
increment: () => void;
decrement: () => void;
reset: () => void;
}
export const useCounterStore = create<CounterState>()(
devtools(
(set) => ({
count: 0,
increment: () => set((state) => ({ count: state.count + 1 }), false, 'increment'),
decrement: () => set((state) => ({ count: state.count - 1 }), false, 'decrement'),
reset: () => set({ count: 0 }, false, 'reset'),
}),
{ name: 'CounterStore' }
)
);
2. Smart Code Actions
Right-click on any store and get intelligent refactoring options:
- Wrap with devtools β Add Redux DevTools integration instantly
- Wrap with persist β Add localStorage persistence
- Add useShallow β Optimize your selectors for performance
- Extract to Slices Pattern β Modularize large stores
3. Real-Time Hover Documentation
Hover over any Zustand function and get:
- π Detailed description
- π TypeScript signature
- π» Usage examples
- β‘ Performance tips
- π Links to official docs
4. Intelligent Auto-Imports
Start typing and get smart import suggestions for:
-
create,createStore,useStore -
devtools,persist,immer -
useShallow(with performance hints!) -
StateCreator,StoreApitypes
5. Command-Driven Store Generation
Use the Command Palette (Ctrl+Shift+P) to:
- Create New Store β Interactive store generator
- Create New Slice β Generate slice files
- Generate Slices Pattern Store β Full project structure
β‘ Performance Best Practices Built-In
Zustand Copilot doesn't just help you write code faster β it helps you write better code.
useShallow Everywhere
// β Bad: Creates new object on every render
const { name, age } = useStore((state) => ({
name: state.name,
age: state.age
}));
// β
Good: Shallow comparison prevents re-renders
const { name, age } = useStore(
useShallow((state) => ({
name: state.name,
age: state.age
}))
);
The extension will warn you when you forget useShallow and offer to add it automatically!
Slices Pattern for Scale
For large applications, the extension encourages the Slices Pattern:
src/stores/
βββ index.ts # Combined store
βββ slices/
βββ authSlice.ts # Authentication
βββ userSlice.ts # User data
βββ settingsSlice.ts # Settings
Use the Zustand: Generate Slices Pattern Store command to scaffold this instantly.
π Getting Started
Installation
- Open VS Code
- Press
Ctrl+Shift+Xto open Extensions - Search for "Zustand Copilot"
- Click Install
Or install via CLI:
code --install-extension devplusfun.zustand-copilot
Quick Start
- Create a new
.tsor.tsxfile - Type
zstoreand pressTab - Fill in the placeholders
- Start building! π»
π Available Snippets
| Snippet | Description |
|---|---|
zstore |
Basic store with devtools |
zslice |
Slice for Slices Pattern |
zpersist |
Persisted store |
zasync |
Async store with loading |
zimmer |
Immer middleware store |
zslices |
Combined slices store |
zshallow |
useShallow selector |
zselector |
Memoized selector |
zsubscribe |
Store subscription |
zgetstate |
Access state outside React |
zcontext |
Context pattern store |
zcomputed |
Computed properties |
zreset |
Store with reset |
zmiddleware |
Full middleware stack |
zactions |
Separate actions interface |
ztemporal |
Undo/redo with zundo |
π Configuration
Customize the extension in your VS Code settings:
{
"zustandCopilot.autoImport.enabled": true,
"zustandCopilot.hoverDocs.enabled": true,
"zustandCopilot.codeActions.enabled": true,
"zustandCopilot.defaultStorePath": "src/stores",
"zustandCopilot.useShallowByDefault": true,
"zustandCopilot.includeDevtools": true
}
π Feedback Welcome!
This is just version 1.0.0, and I have big plans for future releases:
- π Store visualization panel
- π§ͺ Testing utilities
- π Redux β Zustand migration tools
- π Performance analysis
What features would you like to see? Drop a comment below or open an issue on GitHub!
π Links
- π¦ VS Code Marketplace
- π Zustand Official Docs
If this extension helps your Zustand development, please β star the repo and leave a review on the marketplace! It really helps others discover it.
Happy coding! π»β¨
Top comments (0)