Back to articles
Zustand Has a Free State Manager That Replaces Redux in 10 Lines

Zustand Has a Free State Manager That Replaces Redux in 10 Lines

via Dev.to ReactAlex Spinov

Redux needs actions, reducers, selectors, middleware, and 200 lines of boilerplate for a counter. Zustand needs 10 lines. Same power, zero ceremony. What Zustand Gives You for Free Minimal API — create store in 5 lines, use it anywhere No boilerplate — no actions, reducers, dispatchers, or context providers No Provider wrapper — just import and use TypeScript-first — fully typed without extra config Middleware — persist, devtools, immer, subscriptions 1KB gzipped — vs Redux Toolkit's 30KB+ Quick Start npm install zustand Your First Store (10 Lines) import { create } from ' zustand ' ; interface CounterStore { count : number ; increment : () => void ; decrement : () => void ; reset : () => void ; } const useCounter = create < CounterStore > (( set ) => ({ count : 0 , increment : () => set (( state ) => ({ count : state . count + 1 })), decrement : () => set (( state ) => ({ count : state . count - 1 })), reset : () => set ({ count : 0 }), })); Using It (No Provider Needed) // ANY compon

Continue reading on Dev.to React

Opens in a new tab

Read Full Article
2 views

Related Articles