Created
May 30, 2019 19:07
-
-
Save Kurzdor/59203d378fa82f7874719b3606bd2437 to your computer and use it in GitHub Desktop.
useElYOverflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const useElYOverflow = (ref, offset) => { | |
useEffect(() => { | |
const checkOverflow = () => { | |
const isOverflowing = | |
ref.current.offsetHeight + offset * 2 > window.innerHeight | |
if (isOverflowing) { | |
ref.current.classList.add('overflowing') | |
return | |
} | |
ref.current.classList.remove('overflowing') | |
} | |
const handleResize = () => { | |
checkOverflow() | |
} | |
checkOverflow() | |
window.addEventListener('resize', handleResize) | |
return () => { | |
window.removeEventListener('resize', handleResize) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment