React › State Management Libraries (Redux, Zustand & Recoil)
How does Zustand offer a simpler alternative to Redux for managing global state?
IntermediateAnswer
Zustand lets you create a shared store using a simple function, without needing separate actions, reducers, or a Provider wrapping your app. Components read exactly the pieces of state they need directly from a custom hook the store gives you, making the overall setup much shorter and easier to understand.
import { create } from 'zustand';
const useCartStore = create((set) => ({
items: [],
addItem: (item) => set((state) => ({ items: [...state.items, item] })),
}));
function Cart() {
const items = useCartStore((state) => state.items);
return <p>You have {items.length} items</p>;
}Real-world example A team switches their shopping cart state from Redux to Zustand, cutting the amount of setup code significantly while keeping the same reliable shared state behavior across the whole app.