Releases: udecode/zustand-x
[email protected]
[email protected]
[email protected]
Major Changes
-
#100 by @zbeyens – The store hooks are now part of the public API. Previously accessible only through the
store
object, they are now available as standalone hooks to ensure compatibility with the new React Compiler. Added standalone hooks:useStoreValue
,useStoreState
,useTracked
,useTrackedStore
.We're moving away from object namespaces like
use
,get
,set
to a more functional approach where the first argument is the store state field. This includes the extended selectors and actions, where the parameters follow the first argument. This change simplifies the API and makes it more consistent with React hooks. Instead of accessing state through object properties (store.use.name()
), we now use functions with the state field as the first argument (store.useValue('name')
).Migration cases:
// Before: store.use.name(), store.use.extendedSelector(1, 2, (a, b) => a === b) useStoreValue(store, 'name'); useStoreValue(store, 'extendedSelector', 1, 2, (a, b) => a === b); // Equivalent to store.useValue('name'); store.useValue('extendedSelector', 1, 2, (a, b) => a === b); // Before: store.useTracked.name() useTracked(store, 'name'); // Equivalent to store.useTracked('name'); // Before: store.get.name(), store.get.extendedSelector(1, 2), store.get.state() store.get('name'); store.get('extendedSelector', 1, 2); store.get('state'); // Before: store.set.name('value'), store.set.extendedAction(1, 2), store.set.state(draft => { ... }) store.set('name', 'value'); store.set('extendedAction', 1, 2); store.set('state', (draft) => {}); // Before: store.extendSelectors((set, get, api) => ({ ... })). Now only api argument that you can destructure. store.extendSelectors(({ get }) => ({ ... })); // Before: store.extendActions((set, get, api) => ({ ... })). Now only api argument that you can destructure. store.extendActions(({ set }) => ({ ... }));
- Remove
mapValuesKey
. This would be the equivalent:
const stores = { auth: authStore, combobox: comboboxStore, }; useValue(stores.auth, 'name'); useValue(stores.combobox, 'name');
- Remove
[email protected]
Patch Changes
- #95 by @imarabinda –
- fix: missing export
mapValuesKey
- fix: missing export
[email protected]
Major Changes
-
#92 by @imarabinda –
- Added support for Zustand 4.5.0+.
mutative
support. Passmutative: true
in the options.
Migration Instructions
Update the Store Initialization:
-
Replace the old method of initializing the store with the new API.
const store = createStore( () => ({ name: 'zustandX', stars: 0, }), { name: 'repo', immer: true, } );
or
const store = createStore( { name: 'zustandX', stars: 0, }, { name: 'repo', immer: true, } );
-
Ensure to pass the configuration object with name and other options as needed.
-
If your application relies on immer, enable it by passing immer: true in the configuration object.
const store = createStore( () => ({ name: 'zustandX', stars: 0, }), { name: 'repo', immer: true, } );
-
With the new version, integrating middlewares has also changed. Here's how to upgrade your middleware usage:
const store = createStore( middlewareWrapHere(() => ({ name: 'zustandX', stars: 0, })), { name: 'repo', immer: true, } );
[email protected]
[email protected]
[email protected]
[email protected]
Patch Changes
- #69 by @zbeyens –
- Fixes #60 –
[DEPRECATED] Passing a vanilla store will be unsupported in a future version
- Support
equalityFn
towards v5. See https://github.com/pmndrs/zustand/discussions/1937.
- Fixes #60 –