tweak-tools
Version:
Tweak your React projects until awesomeness
22 lines (21 loc) • 850 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useValuesForPath = void 0;
const shallow_1 = __importDefault(require("zustand/shallow"));
const data_1 = require("../utils/data");
/**
* Hook that returns the values from the zustand store for the given paths.
* @param paths paths for which to return values
* @param initialData
*/
function useValuesForPath(store, paths, initialData) {
const valuesForPath = store.useStore((s) => {
const data = Object.assign(Object.assign({}, initialData), s.data);
return (0, data_1.getValuesForPaths)(data, paths);
}, shallow_1.default);
return valuesForPath;
}
exports.useValuesForPath = useValuesForPath;