refun
Version:
A collection of React Hook-enabled functions that compose harmoniously with each other. Similar to `recompose`, but:
17 lines (15 loc) • 605 B
JavaScript
import { useRef } from 'react';
import { EMPTY_OBJECT } from 'tsfn';
import { shallowEqualByKeys } from './utils';
export var mapWithPropsMemo = function mapWithPropsMemo(getFn, watchKeys) {
return function (props) {
var prevProps = useRef(EMPTY_OBJECT);
var prevResult = useRef(EMPTY_OBJECT);
if (prevResult.current === EMPTY_OBJECT || !shallowEqualByKeys(prevProps.current, props, watchKeys)) {
prevProps.current = props;
prevResult.current = getFn(props);
}
return Object.assign({}, props, prevResult.current);
};
};
//# sourceMappingURL=map-with-props-memo.js.map