@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
30 lines • 1.01 kB
JavaScript
//vendors
import React from 'react';
const useIsOverflow = () => {
const [isOverflow, setIsOverflow] = React.useState(false);
const innerRef = React.useRef(null);
React.useEffect(() => {
const element = innerRef.current;
if (!element) {
return () => null;
}
const getOverflow = () => {
const hasOverflow = element.offsetWidth > window.innerWidth;
setIsOverflow(hasOverflow);
};
getOverflow();
window.addEventListener('resize', getOverflow);
return () => window.removeEventListener('resize', getOverflow);
}, []);
return { innerRef, isOverflow };
};
/**
* @description
* Hook to check if the element is overflow
* @param {React.MutableRefObject<HTMLElement | null>} ref - Ref of the element.
* @returns {boolean} - Return if the element is overflow.
* @example
* const {innerRef, isOverflow} = useIsOverflow();
*/
export default useIsOverflow;
//# sourceMappingURL=useIsOverflow.js.map