# Data flow — pmndrs/zustand

> Canonical page: https://codevetter.com/unpack/zustand/data-flow

# Data flow — pmndrs/zustand

Scanned commit d7a5583cffd80af515f7dfb69583c95cbdc9e2ce (2026-09-29). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

State updates enter through values, updater functions, reducers, or middleware-wrapped setters. The vanilla store owns the resulting snapshot and notifies synchronous subscribers; React selects snapshots through its external-store interface. Persistence and DevTools create additional output and input boundaries around that same store.
- setState evaluates function input against current state, skips Object.is-identical results, then replaces or shallow-merges before notifying listeners with new and previous state. — [src/vanilla.ts#L66-L80](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/vanilla.ts#L66-L80)
- subscribe stores callbacks in a Set and returns deletion-based unsubscribe; getInitialState retains the initializer result separately from later state snapshots. — [src/vanilla.ts#L83-L96](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/vanilla.ts#L83-L96)
- useStore supplies selected getState snapshots for clients and selected getInitialState snapshots for server rendering, using the same api.subscribe boundary. — [src/react.ts#L26-L36](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/react.ts#L26-L36)
- Selective subscriptions cache currentSlice and pass next/previous slices only when equalityFn rejects equivalence; useShallow instead stabilizes the selected output reference. — [src/middleware/subscribeWithSelector.ts#L53-L65](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/middleware/subscribeWithSelector.ts#L53-L65) [src/react/shallow.ts#L4-L10](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/react/shallow.ts#L4-L10)
- Persistence wraps both api.setState and the creator's set: each updates live state first, then partializes a shallow copy and writes a state/version envelope under options.name. — [src/middleware/persist.ts#L221-L243](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/middleware/persist.ts#L221-L243)
- createJSONStorage parses storage strings, awaits Promise reads, serializes writes with an optional replacer, and delegates removal to the selected adapter. — [src/middleware/persist.ts#L31-L60](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/middleware/persist.ts#L31-L60)
- Hydration checks stored versions, optionally migrates, merges with the latest available state, replaces live state, writes migrated data, and then signals completion unless its generation is obsolete. — [src/middleware/persist.ts#L270-L310](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/middleware/persist.ts#L270-L310) [src/middleware/persist.ts#L312-L334](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/middleware/persist.ts#L312-L334)
- DevTools sends actions and current snapshots outward; incoming ACTION and DISPATCH messages can set state or dispatch reducers while setStateFromDevtools temporarily suppresses recording. — [src/middleware/devtools.ts#L216-L243](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/middleware/devtools.ts#L216-L243) [src/middleware/devtools.ts#L258-L263](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/middleware/devtools.ts#L258-L263) [src/middleware/devtools.ts#L308-L354](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/middleware/devtools.ts#L308-L354) [src/middleware/devtools.ts#L356-L395](https://github.com/pmndrs/zustand/blob/d7a5583cffd80af515f7dfb69583c95cbdc9e2ce/src/middleware/devtools.ts#L356-L395)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
