DEV Community

Alex Spinov
Alex Spinov

Posted on

Zustand Has a Free API — Minimal State Management for React Without Boilerplate

What if React state management required no providers, no reducers, no context — just a function call?

Zustand is a tiny state management library for React. It has 47K+ GitHub stars and is the most downloaded React state manager after Redux.

Why Zustand Over Redux

  • No providers — no <Provider> wrapper needed
  • No boilerplate — no actions, reducers, or action types
  • 1 KB — smaller than useState in many cases
  • Works outside React — use in vanilla JS, Node.js, tests
  • Middleware — persist, devtools, immer built in

Quick Start

npm install zustand
Enter fullscreen mode Exit fullscreen mode
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 }),
}));

// Use anywhere — no Provider needed!
function Counter() {
  const count = useCounter((state) => state.count);
  const increment = useCounter((state) => state.increment);
  return <button onClick={increment}>{count}</button>;
}
Enter fullscreen mode Exit fullscreen mode

Persist State

import { persist } from "zustand/middleware";

const useSettings = create(
  persist(
    (set) => ({
      theme: "light",
      language: "en",
      setTheme: (theme: string) => set({ theme }),
    }),
    { name: "settings-storage" } // localStorage key
  )
);
Enter fullscreen mode Exit fullscreen mode

Real Use Case

A team replaced Redux Toolkit in their dashboard app. They deleted 2,400 lines of Redux boilerplate — action creators, reducers, selectors, slice files. The Zustand equivalent was 200 lines. Feature development velocity doubled because adding state no longer required touching 5 files.

When to Use Zustand

  • Any React app needing global state
  • Replacing Redux when you want less boilerplate
  • Shared state across unrelated components
  • State that needs persistence or devtools

Get Started

Visit zustand-demo.pmnd.rs — 1KB, zero config, MIT licensed.


Need custom data pipelines or scraping solutions? Check out my Apify actors or email me at spinov001@gmail.com for custom solutions.

Top comments (0)