designwithfocus

JavaScript & front end

What Is Zustand? A Small Store for React State

By Design With Focus Team 6 min read
A small store hook feeding a counter component on a React screen

Short answer

Zustand is a small state store for React whose public API is a hook you create with create(). The docs call it a bearbones solution that is explicit and flux-like, and they say you can use the hook without a provider. Selecting a slice re-renders that component when the slice changes. The store can also run outside React.

Last verified against the sources listed below.

Key takeaways

  • The introduction calls Zustand a small, fast, and scalable bearbones state manager with a hooks API.
  • create() returns a hook. set merges state unless you pass true as the second argument.
  • A selector such as state => state.bears re-renders only when that pick changes.
  • The README says equality is strict (old === new) unless you pass useShallow or another compare.
  • Vanilla createStore() returns getState, setState, subscribe, and getInitialState, not a hook.
  • The repository package.json on main lists version 5.1.0 and marks the package private.

A plain answer to what is zustand starts with the hook, not with a framework install. The Zustand introduction calls it a small, fast, and scalable bearbones state management solution, with a comfy API based on hooks, enough convention to be explicit and flux-like, and not much boilerplate.

The docs home shortens that to a tiny, predictable store with hooks-first ergonomics. It also says the store works across React, React Native, and non-React environments, and that devtools, persistence, Redux-style middleware, and Immer are opt-in. The home page says the footprint is small. It does not print a kilobyte size.

What is Zustand?

Zustand is a React state store you create once and read through a hook.

React’s homepage calls React the library for web and native user interfaces and says those interfaces are built from components. Zustand does not replace that library. It holds state those components can select. The GitHub README describes the same project as bear necessities for state management in React, under the MIT license.

The introduction spends time on three pitfalls it says the store was written to handle: the zombie child problem, React concurrency, and context loss between mixed renderers. Those are the reasons the docs give for taking the library seriously. They are not a benchmark against every other store.

As of December 2026, the package.json on main lists version 5.1.0. The same file sets "private": true, so that field is the repository version, not a sentence on the npm registry. Install instructions on the docs are npm install zustand, plus the yarn, pnpm, bun, and deno equivalents.

How do you create a store?

Call create from zustand and pass a function that receives set.

The introduction says the store is a hook, and that you can put primitives, objects, and functions in it. The set function merges state. In the sample, bears starts at 0, increasePopulation calls set with the previous state plus one bear, and removeAllBears calls set with bears: 0.

import { create } from 'zustand'
const useBear = create((set) => ({
  bears: 0,
  increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
  removeAllBears: () => set({ bears: 0 }),
}))

The README adds a second argument to set. It defaults to false, which means merge. Pass true and set replaces the state model instead.

The sample warns that a replace can wipe actions if you pass an empty object. Read state from inside an action with get, which the README shows beside set.

That is the whole setup for a single store. You do not wrap the tree before the first component calls the hook. JavaScript is the language of that callback, whether the file is plain JavaScript or the TypeScript form the README shows later.

How do components read state?

Call the hook with a selector. The component re-renders when that selected value changes.

The introduction’s counter does useBear((state) => state.bears) and renders the number. A second component selects only increasePopulation and puts it on a button. The docs say you can use the hook anywhere, without providers.

The README says the default change check is strict equality, old === new, which fits atomic picks such as a number or a function. If you build a new object inside the selector, that object fails === every time. useShallow from zustand/react/shallow compares the pick shallowly so the component skips a render when the contents did not change.

You can also pass your own equality function. The README says that form uses createWithEqualityFn.

Selecting the whole store, useBear() with no selector, is allowed and costly. The README says it will update the component on every state change. Pick the fields the component paints.

What else can the store do?

The hook also exposes getState, setState, and subscribe for code that is not a component.

The README says those utilities sit on the hook, and it tells you not to use that pattern to add state in React Server Components. For a store with no React at all, import createStore from zustand/vanilla. The README says the only difference is that createStore returns the API utilities instead of a hook: getState, setState, subscribe, and getInitialState.

useStore can bind a vanilla store to a component. The README says that hook has been available since v4.

Middleware is how the extra behavior is packaged. persist stores the slice. devtools logs actions to the Redux DevTools extension, and it can disable itself with enabled: false.

immer lets a recipe mutate a draft. redux wires a reducer and adds dispatch. subscribeWithSelector lets subscribe take a selector and a callback.

The docs home lists the same set as opt-in tools, not as required setup.

Transient updates use subscribe to write into a ref without rendering. The README says to pair that with useEffect so the listener leaves on unmount, and that it matters when the view can change without a React render. That is a specialized path. Most screens should keep the selector.

How does it differ from context?

The README’s own comparison says Zustand uses less boilerplate than context and renders only on changes.

API What the README or docs say
create() Returns a hook. No provider is required for the basic store.
set Merges state. A second argument of true replaces the model.
Selector Re-renders when the pick changes. Default check is old === new.
createStore Vanilla store. Returns utilities, not a hook.
useStore Binds a vanilla store. The README says it has been available since v4.

Against Redux, the same file lists a simple API, hooks as the way you read state, no context provider around the app, and a way to tell components about a change without a render. Those are the project’s claims about its shape. They are not a timing table.

Context still shows up when you need more than one store of the same kind, or a store built from props. The README’s recommended method, since v4, is a vanilla store on a React context, read with useStore. Passing the hook itself as a context value can break the rules of hooks, which is why that section steers you to the vanilla store.

A component still has to exist before the store has anything to show. The SVG to JSX tool turns an SVG into a React component, which is the UI layer a Zustand store can sit behind. The store does not parse the SVG. It can hold the flag, the count, or the selected id that component reads.

Frequently asked questions

Does the store need a React provider?

The basic store does not. The introduction says you can use the hook anywhere, without providers, and the component re-renders when the selected state changes. The README still shows a context pattern for dependency injection or for a store that must start from props. In that pattern you put a vanilla store on a context and read it with useStore. That is optional structure, not the default.

Where does persist write by default?

The README's persist example passes createJSONStorage with sessionStorage and comments that localStorage is the default when you omit storage. The name field is the key in that storage, and the comment says the name must be unique. Persist is middleware you opt into. A store created with create() alone does not write to the browser.

What is the React Server Component warning?

The README says getState and setState on the hook are not recommended for adding state in React Server Components, typically in Next.js 13 and above. It says that pattern can lead to unexpected bugs and privacy issues. The recommended context method, available since v4 in that README, uses a vanilla store instead of passing the hook through context.

Can actions be async?

Yes. The README says to call set when you are ready, and that Zustand does not care whether the action is async. The sample awaits a fetch and then calls set with the JSON. Nothing in that section queues the promise for you. You still handle errors in the action you wrote.

Which React does the homepage describe?

The React homepage calls React the library for web and native user interfaces and says you build those interfaces from components. The page header shows React v 19.3. Zustand's own docs say the same store surface works across React, React Native, and non-React code. The version on the React site is not a Zustand version.

Sources