refun
Version:
A collection of React Hook-enabled functions that compose harmoniously with each other. Similar to `recompose`, but:
17 lines (15 loc) • 559 B
JavaScript
import { useRef } from 'react';
import { EMPTY_OBJECT } from 'tsfn';
import { shallowEqualByKeys } from './utils';
export var onChange = function onChange(getFn, watchKeys) {
return function (props) {
var prevPropsRef = useRef(EMPTY_OBJECT);
if (prevPropsRef.current === EMPTY_OBJECT || !shallowEqualByKeys(prevPropsRef.current, props, watchKeys)) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
getFn(props);
}
prevPropsRef.current = props;
return props;
};
};
//# sourceMappingURL=on-change.js.map