DEV Community

Alex Spinov
Alex Spinov

Posted on

Zustand Has a Free State Management Library — Simpler Than Redux, More Powerful Than Context

A React developer set up Redux for global state. Store, reducers, actions, selectors, middleware, thunks - 200 lines of boilerplate for a counter.

Zustand is state management in 5 lines. No providers, no reducers, no boilerplate. Just a store and a hook.

What Zustand Offers for Free

  • Minimal API - create() + useStore() is all you need
  • No Provider - No wrapping your app in Context
  • TypeScript - Full type inference
  • Middleware - Persist, immer, devtools, subscribeWithSelector
  • Slices - Split store into slices for large apps
  • Transient Updates - Update without re-rendering
  • Tiny - 1KB gzipped

Quick Start

import { create } from 'zustand'

const useStore = create((set) => ({
  count: 0,
  increment: () => set((state) => ({ count: state.count + 1 })),
  decrement: () => set((state) => ({ count: state.count - 1 })),
}))

function Counter() {
  const { count, increment } = useStore()
  return <button onClick={increment}>{count}</button>
}
Enter fullscreen mode Exit fullscreen mode

That is it. No Provider. No reducer. No action types.

GitHub: pmndrs/zustand - 49K+ stars


Need to monitor and scrape data from multiple web services automatically? I build custom scraping solutions. Check out my web scraping toolkit or email me at spinov001@gmail.com for a tailored solution.

Top comments (0)