Last active
July 8, 2021 09:41
-
-
Save tjinlag/e32222874c511bfc3edd824f6e8a5523 to your computer and use it in GitHub Desktop.
React Custom Hook: don't allow scroll window
This file contains 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
export const useDisableScroll = () => { | |
useEffect(() => { | |
const { body } = document; | |
const bodyStyle = { ...body.style }; | |
body.style.height = '100%'; | |
body.style.overflow = 'hidden'; | |
body.style.position = 'relative'; | |
return () => { | |
body.style.height = bodyStyle.height; | |
body.style.overflow = bodyStyle.overflow; | |
body.style.position = bodyStyle.position; | |
}; | |
}, []); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment