@winglet/react-utils
Version:
React utility library providing custom hooks, higher-order components (HOCs), and utility functions to enhance React application development with improved reusability and functionality
32 lines (28 loc) • 972 B
JavaScript
;
var react = require('react');
const useRestProperties = (props) => {
const propsRef = react.useRef(props);
const keysRef = react.useRef(props ? Object.keys(props) : []);
return react.useMemo(() => {
if (!props || props === propsRef.current)
return props;
const keys = Object.keys(props);
const length = keys.length;
if (length !== keysRef.current.length) {
propsRef.current = props;
keysRef.current = keys;
return props;
}
if (length === 0)
return propsRef.current;
for (let i = 0, k = keys[0], l = keys.length; i < l; i++, k = keys[i]) {
if (props[k] !== propsRef.current[k]) {
propsRef.current = props;
keysRef.current = keys;
return props;
}
}
return propsRef.current;
}, [props]);
};
exports.useRestProperties = useRestProperties;