UNPKG

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.

29 lines (27 loc) 786 B
// 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; }; export { withArraySelector };