zustand-ards
Version:
A library of simple opinionated utilities for zustand. zustand-ards are typesafe and designed to be easily added to an existing codebase to improve the experience of developing with zustand.
31 lines (28 loc) • 818 B
JavaScript
;
// src/array-selector.ts
var withArraySelector = (storeHook) => {
function storeHookWithArraySelector(selector, equals) {
if (!selector) {
return storeHook();
}
if (typeof selector === "function") {
return storeHook(selector, equals);
}
const selectorFunction = (state) => {
const selection = {};
selector.forEach((key) => {
selection[key] = state[key];
});
return selection;
};
return storeHook(
selectorFunction,
equals
);
}
storeHookWithArraySelector.getInitialState = storeHook.getInitialState;
storeHookWithArraySelector.getState = storeHook.getState;
storeHookWithArraySelector.subscribe = storeHook.subscribe;
return storeHookWithArraySelector;
};
exports.withArraySelector = withArraySelector;