Created
November 3, 2020 21:20
-
-
Save gaurangrshah/d602a07c42e4a8eb96b5ef1ce7610a62 to your computer and use it in GitHub Desktop.
#react #hooks
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
import { useLayoutEffect } from "react" | |
export const useBodyScrolllock = toggle => { | |
useLayoutEffect(() => { | |
let originalStyle | |
let lockScroll = !toggle ? false : true | |
if (lockScroll) { | |
originalStyle = window.getComputedStyle(document.body).overflow | |
document.body.style.overflow = "hidden" | |
} | |
return () => (document.body.style.overflow = originalStyle) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment