refun
Version:
A collection of React Hook-enabled functions that compose harmoniously with each other. Similar to `recompose`, but:
26 lines (19 loc) • 675 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mapWithPropsMemo = void 0;
var _react = require("react");
var _tsfn = require("tsfn");
var _utils = require("./utils");
const mapWithPropsMemo = (getFn, watchKeys) => props => {
const prevProps = (0, _react.useRef)(_tsfn.EMPTY_OBJECT);
const prevResult = (0, _react.useRef)(_tsfn.EMPTY_OBJECT);
if (prevResult.current === _tsfn.EMPTY_OBJECT || !(0, _utils.shallowEqualByKeys)(prevProps.current, props, watchKeys)) {
prevProps.current = props;
prevResult.current = getFn(props);
}
return { ...props,
...prevResult.current
};
};
exports.mapWithPropsMemo = mapWithPropsMemo;