What problem does it solve?
This skill eliminates the complexity and inconsistency often found in Zustand store implementations by enforcing a standardized, type-safe StoreBuilder pattern. It ensures all stores follow best practices, saving development time and reducing debugging efforts.
Core Features & Use Cases
- Standardized StoreBuilder Pattern: Enforces a consistent, type-safe approach for all Zustand stores, separating state from actions.
- Immer Middleware Integration: Simplifies immutable state updates, allowing direct mutations on draft state.
- Optional Persistence: Supports fine-grained control over state persistence across sessions.
- Use Case: When building a new feature in a React application that requires client-side state, use this skill to quickly scaffold a new Zustand store that adheres to all architectural standards, complete with persistence and type safety.
Quick Start
Initialize StoreBuilder with initial state
const { set, createFactory } = StoreBuilder<Omit<MyStoreState, 'setValue' | 'addItem'>>(
{
value: 0,
items: [],
}
);
Create factory with actions
const useMyStore = createFactory({
setValue: (v: number) => set((state) => { state.value = v; }),
addItem: (item: string) => set((state) => { state.items.push(item); }),
});