UNPKG

@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) 994 B
'use strict'; 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 currentKeys = Object.keys(props); if (currentKeys.length !== keysRef.current.length) { propsRef.current = props; keysRef.current = currentKeys; return props; } if (!currentKeys.length) return propsRef.current; for (let i = 0; i < currentKeys.length; i++) { const key = currentKeys[i]; if (props[key] !== propsRef.current[key]) { propsRef.current = props; keysRef.current = currentKeys; return props; } } return propsRef.current; }, [props]); }; exports.useRestProperties = useRestProperties;