Skip to content

Instantly share code, notes, and snippets.

@tjinlag
Last active July 8, 2021 09:41
Show Gist options
  • Save tjinlag/e32222874c511bfc3edd824f6e8a5523 to your computer and use it in GitHub Desktop.
Save tjinlag/e32222874c511bfc3edd824f6e8a5523 to your computer and use it in GitHub Desktop.
React Custom Hook: don't allow scroll window
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