Zustand is a minimalist state management library that is simpler than Redux, but more powerful than Context.
Simple analogy: Redux is like a huge office with bureaucracy (action types, reducers, dispatch, middleware). Zustand is like a notepad on the desk: wrote it — everyone saw it. Simple and fast.
Key differences from Redux:
<Provider> — just import and use.What it looks like:
1import { create } from 'zustand';23// Create store4const useStore = create((set) => ({5 count: 0,6 user: null,78 increment: () => set((state) => ({ count: state.count + 1 })),9 setUser: (user) => set({ user }),10}));1112// In component13function Counter() {14 const count = useStore((state) => state.count);15 const increment = useStore((state) => state.increment);1617 return <button onClick={increment}>{count}</button>;18}
Additionally:
When to choose what: