CodeVetter · Repo Unpack · System map
pmndrs/zustand
The package separates a framework-independent store from React consumers and opt-in middleware. State lives in memory unless a consumer supplies persistence middleware and storage. Rollup produces CommonJS, ESM, and declarations; GitHub Actions describes validation, package publication, previews, and documentation deployment.
- src/index.ts exports vanilla and React APIs; middleware, traditional equality hooks, and shallow helpers have separate source entrypoints.
- createStoreImpl owns state and listeners in a closure and exposes setState, getState, getInitialState, and subscribe through StoreApi.
- React useStore consumes a read-only StoreApi subset through useSyncExternalStore; traditional hooks instead import the with-selector shim.
- Persistence defaults to browser localStorage, while PersistStorage permits consumer-supplied synchronous or asynchronous storage adapters.
- The export map selects CommonJS or ESM JavaScript and corresponding declarations, including react-native conditions; React, Immer, and the selector shim are optional peers.
- Rollup selects src entrypoints from config flags and emits dist/*.js plus dist/esm/*.mjs; postbuild patches declarations and creates a publishable dist manifest.
- The two private Vite examples use the React SWC plugin; demo includes Three.js integrations, whereas starter contains a typed counter.
- Release publication builds and publishes dist to npm; preview CI publishes dist through pkg-pr-new, and docs CI delegates building to pmndrs/docs before deploying GitHub Pages.