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