UNPKG

tweak-tools

Version:

Tweak your React projects until awesomeness

24 lines (23 loc) 887 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useValues = exports.useValue = void 0; const shallow_1 = __importDefault(require("zustand/shallow")); const context_1 = require("../context"); const useValue = (path) => { return (0, exports.useValues)([path])[path]; }; exports.useValue = useValue; const useValues = (paths) => { const store = (0, context_1.useStoreContext)(); const value = store.useStore(({ data }) => paths.reduce((acc, path) => { // @ts-expect-error if (data[path] && 'value' in data[path]) return Object.assign(acc, { [path]: data[path].value }); return acc; }, {}), shallow_1.default); return value; }; exports.useValues = useValues;