Guide
Zustand vs Legend-State vs Valtio 2026



Comparing React state managers — Zustand's simplicity, Legend-State's fine-grained reactivity and offline-first sync, and Valtio's proxy magic for 2026.
Contents
Contents
TL;DR
Start with Zustand when your React app needs a shared store and explicit selectors. Evaluate Legend-State if you need observable fields and sync plugins for offline edits. Choose Valtio if you prefer mutating a proxy and tracking the properties a component reads. Zustand store API · Legend-State sync guide · Valtio snapshot API
Key Takeaways
- Zustand supports local persistence and Redux DevTools through middleware. Persistence · Redux DevTools
- Legend-State can persist local changes and retry pending writes with a configured sync plugin. Persist and Sync
- Valtio tracks which snapshot properties a component reads. Write changes through the original proxy. Valtio snapshot API
Downloads
| Package | npm downloads, Nov 23–29, 2026 |
|---|---|
zustand | 88,350,372 |
valtio | 2,985,517 |
@legendapp/state | 148,152 |
jotai | 9,915,523 |
mobx | 4,366,625 |
These totals cover all versions of each npm package and include dependency installs.
Zustand: The Reliable Default
Zustand gives React components a shared store. Add persist for local storage or devtools for Redux DevTools when you need them. Persistence · Redux DevTools
The core API is a single function: create(). You define a store as a function that receives set and get, return your initial state and actions, and you're done. There are no actions to dispatch, no reducers to write, no providers to wrap your tree in. You call the hook directly and access whatever slice you need.
A selector such as state => state.items.length subscribes to the derived count. When selecting several fields into a new object, wrap the selector with useShallow to reuse its previous result when the top-level values are shallowly equal. Zustand useShallow reference
// npm install zustand
import { create } from 'zustand';
import { persist, devtools } from 'zustand/middleware';
interface CartStore {
items: CartItem[];
total: number;
addItem: (item: CartItem) => void;
removeItem: (id: string) => void;
clearCart: () => void;
}
export const useCartStore = create<CartStore>()(
devtools(
persist(
(set, get) => ({
items: [],
total: 0,
addItem: (item) => set((state) => {
const items = [...state.items, item];
return { items, total: items.reduce((sum, i) => sum + i.price, 0) };
}),
removeItem: (id) => set((state) => {
const items = state.items.filter(i => i.id !== id);
return { items, total: items.reduce((sum, i) => sum + i.price, 0) };
}),
clearCart: () => set({ items: [], total: 0 }),
}),
{ name: 'cart-storage' } // Persists to localStorage
)
)
);
// Usage — component only re-renders when accessed slice changes:
function CartCount() {
const count = useCartStore(state => state.items.length); // Only subscribes to length
return <span>{count}</span>;
}
function CartTotal() {
const total = useCartStore(state => state.total); // Only subscribes to total
return <span>${total.toFixed(2)}</span>;
}
Zustand also works completely outside of React. You can read or write state from event listeners, WebSocket callbacks, or server actions simply by calling useCartStore.getState() or useCartStore.setState(). This makes it useful for coordinating state across parts of your application that don't live in React components, like analytics handlers or background sync logic.
The middleware ecosystem is mature. persist handles localStorage or any storage adapter. devtools wires up Redux DevTools. immer lets you write mutations in a draft-based style. subscribeWithSelector gives you fine-grained subscriptions outside React. Between these, virtually every state management pattern is covered without leaving the Zustand API.
Zustand's Auth Store Pattern
A common pattern that Zustand handles elegantly is authentication state combined with async loading:
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
interface AuthStore {
user: User | null;
token: string | null;
isLoading: boolean;
login: (email: string, password: string) => Promise<void>;
logout: () => void;
refreshToken: () => Promise<void>;
}
export const useAuthStore = create<AuthStore>()(
persist(
(set, get) => ({
user: null,
token: null,
isLoading: false,
login: async (email, password) => {
set({ isLoading: true });
try {
const { user, token } = await api.auth.login({ email, password });
set({ user, token, isLoading: false });
} catch (error) {
set({ isLoading: false });
throw error;
}
},
logout: () => set({ user: null, token: null }),
refreshToken: async () => {
const { token } = get();
if (!token) return;
const refreshed = await api.auth.refresh(token);
set({ token: refreshed.token });
},
}),
{
name: 'auth-storage',
partialize: (state) => ({ token: state.token }), // Only persist token
}
)
);
Legend-State: Fine-Grained Reactivity
Legend-State makes individual values observable. For a table with frequent row updates, put the field reads inside the row components so the subscriptions follow those reads. Profile the table with the same update workload before choosing a library. Legend-State React API
The observable() function is the entry point. You pass it a plain object and get back a deeply reactive graph. Access values with .get(), update them with .set(). Components wrapped with the observer() higher-order component automatically subscribe to every observable they access during render.
The Legend-State examples are illustrative and use the v3 beta. The npm latest tag still points to the stable v2 line. Pin the release you are evaluating before copying the sync imports. Legend-State installation · npm latest
// npm install @legendapp/state@beta
import { observable } from '@legendapp/state';
import type { Observable } from '@legendapp/state';
import { observer } from '@legendapp/state/react';
// Observable state — fine-grained tracking:
const cartStore = observable({
items: [] as CartItem[],
get total() {
return this.items.reduce((sum, item) => sum + item.price.get() * item.qty.get(), 0);
},
});
// observer() HOC — component re-renders only for accessed observables:
const CartItemRow = observer(function CartItemRow({ item }: { item: Observable<CartItem> }) {
return (
<div>
{/* Only re-renders when this item's name changes: */}
<span>{item.name.get()}</span>
<button onClick={() => item.qty.set(v => v + 1)}>+</button>
</div>
);
});
Legend-State's Killer Feature: Sync Plugins
Legend-State's sync plugins can load persisted state and send changes to a remote service. Configure persistence and retry behavior explicitly. For offline edits, test what happens when the app restarts with a pending write and when another client changes the same record. Legend-State sync guide
import { observable } from '@legendapp/state';
import { ObservablePersistLocalStorage } from '@legendapp/state/persist-plugins/local-storage';
import { synced } from '@legendapp/state/sync';
// fetchDraft and saveDraft are supplied by the application.
const draft$ = observable(
synced({
initial: { title: '' },
get: fetchDraft,
set: ({ value }) => saveDraft(value),
persist: {
name: 'draft',
plugin: ObservablePersistLocalStorage,
retrySync: true,
},
retry: { infinite: true },
})
);
draft$.title.set('New title');
The trade-off is API complexity. Legend-State's .get() / .set() pattern is different from what most React developers expect, and the observer() HOC adds a wrapping step. The library is also newer and smaller than Zustand's ecosystem, so community resources and third-party middleware are more limited. But for applications where fine-grained reactivity or offline sync is a core requirement, Legend-State's capabilities are unique in the React ecosystem.
Valtio: Proxy Magic
Pass a plain object to proxy() and update its properties directly. Read the proxy through useSnapshot() in React. Valtio proxy API · Valtio snapshot API
The core API has two functions. proxy() creates a reactive state object. useSnapshot() subscribes a React component to a read-only snapshot of that state, automatically tracking which properties were accessed during render and only triggering re-renders when those specific properties change.
// npm install valtio
import { proxy, useSnapshot } from 'valtio';
// Create state with plain object — mutations via proxy:
const cartState = proxy({
items: [] as CartItem[],
get total() {
return this.items.reduce((sum, item) => sum + item.price * item.qty, 0);
},
});
// Mutations are just assignments (proxy intercepts them):
function addToCart(item: CartItem) {
cartState.items.push(item); // Direct mutation — Valtio tracks it
}
function updateQty(id: string, qty: number) {
const item = cartState.items.find(i => i.id === id);
if (item) item.qty = qty; // Direct property set
}
// Component subscribes only to accessed keys:
function CartTotal() {
const snap = useSnapshot(cartState);
// Only re-renders when `total` or accessed `items` change:
return <span>${snap.total.toFixed(2)}</span>;
}
function CartCount() {
const snap = useSnapshot(cartState);
return <span>{snap.items.length}</span>;
}
The mutation model is Valtio's strongest selling point. If you find Zustand's set() pattern unnatural — especially for nested updates — Valtio's direct assignment style is refreshing. There is no spread syntax, no immutability juggling, and no mental model shift between how state looks and how you change it. This makes Valtio particularly attractive for developers migrating from Vue's reactive system or from MobX.
Valtio also supports derived state through computed getters on the proxy object, and it has a subscribe() function for side effects outside of React. The proxyWithHistory and proxySet/proxyMap utilities cover more advanced use cases like undo/redo and typed collection state.
One important constraint: because Valtio relies on JavaScript Proxies, the snapshot you receive in useSnapshot() is immutable. You cannot mutate snap.items.push() — mutations must go through the original cartState proxy. This distinction trips up developers occasionally, but the TypeScript types make it obvious once you understand the pattern.
Performance Comparison
The three libraries handle re-renders differently, and this matters most for high-frequency updates or large lists.
Zustand subscriptions are based on selector return values. If your selector returns a primitive or a stable reference, the component doesn't re-render. The problem arises with object selectors — state => state.user returns the same reference unless user changes, which is fine, but state => ({ name: state.user.name, email: state.user.email }) creates a new object every render. useShallow fixes this with shallow equality, but it's an opt-in optimization you have to remember.
Valtio improves on this with automatic property-level tracking. useSnapshot() tracks which keys of the snapshot you actually read during render and only re-triggers when those specific keys change. You don't write selectors — Valtio figures it out from your render function. This is more ergonomic and harder to accidentally misuse.
Legend-State tracks the observable reads in each component wrapped with observer(). Place reads in the component that displays the field so the list container can avoid subscribing to row data. Legend-State React API
For a large table, record the renders triggered by a change to one row and by a change to the row order. Use the same component boundaries and update pattern for each store.
Package Health Table
| Library | State outside React | Persistence | React subscription |
|---|---|---|---|
| Zustand | createStore | persist middleware | Selector result |
| Valtio | proxy() | Save and restore via a subscription | Accessed snapshot properties |
| Legend-State | observable() | Persistence and sync plugins | Observable reads in observer() |
When to Choose
Choose Zustand for the vast majority of React applications. It has the largest ecosystem, the most tutorials, and the simplest mental model. Zustand's middleware covers persistence, DevTools, and Immer-style mutations. The selector pattern is explicit, which makes subscriptions easy to audit and debug. If you're building a standard SaaS product, dashboard, or e-commerce app, Zustand is the right default.
Choose Legend-State if its observable reads or sync plugins fit your requirements. For offline-first apps, test restart and retry behavior with the persistence plugin and backend you plan to ship. Persist and Sync
Choose Valtio when property assignments fit the way you model nested updates and automatic tracking of snapshot reads fits your React components. Valtio snapshot API
State Outside React Components
All three libraries support reading and writing state outside of React components, which is important for coordinating with non-React code — WebSocket event handlers, browser APIs like beforeunload, or server action callbacks in Next.js.
With Zustand, you call useCartStore.getState() to read and useCartStore.setState() to write outside of components. This makes it trivial to reset state on logout, update state from a WebSocket message handler, or read state from a utility function without passing props down.
With Valtio, you simply mutate the cartState proxy directly — no special API. The proxy is a regular JavaScript object outside of React, so cartState.items.push(item) works the same in an event handler as it does inside a component action function. This consistency is one of Valtio's most underrated qualities.
With Legend-State, you call observable.set() directly on the observable object. Any component currently mounted with observer() that accesses that observable will re-render. The same fine-grained reactivity works outside React — postsStore.data[0].title.set('Updated') will cause only the component rendering that specific post's title to re-render.
Migrating from Redux to Modern State Managers
Many teams are actively migrating away from Redux to Zustand, Valtio, or Legend-State. The migration is typically straightforward for Zustand because the mental model (store with actions, selectors for components) is similar. The main differences are:
Zustand stores are not global by default — each create() call produces an independent store. Redux's single store architecture is replaced by multiple focused stores. Most teams find this more maintainable, but it requires thinking about store boundaries during migration.
Redux action creators become plain functions in Zustand stores — no action types, no dispatch. The set() function is the only mechanism for state changes. If your Redux codebase uses thunks heavily, the equivalent in Zustand is simply an async function in the store that calls set() after awaiting.
Valtio's migration path from Redux is even more direct for teams that found Redux's immutable update patterns cumbersome. Valtio mutations are direct assignments, which feels closer to how many developers naturally think about state changes.
Legend-State migrations are less common because its API is most different from Redux's — the observable() / .get() / .set() pattern requires learning new conventions. But for teams migrating to an offline-first architecture, the sync plugins make the effort worthwhile.
- Compare download trends: Zustand vs Legend-State on PkgPulse
- More state management: Zustand vs Jotai in 2026
- Package health details: Zustand on PkgPulse