Created
October 28, 2019 14:50
-
-
Save csenio/2bfdd84a308e33f1c4445476b0becb75 to your computer and use it in GitHub Desktop.
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
import {useEffect} from 'react' | |
// lock body scroll when modals are open 🔥 | |
// if isLocked isn't specified it will lock the page when mounted | |
function useLockBodyScroll(isLocked = true) { | |
useEffect(() => { | |
const originalStyle = window.getComputedStyle(document.body).overflow | |
if (isLocked) { | |
document.body.style.overflow = 'hidden' | |
} | |
return () => { | |
document.body.style.overflow = originalStyle | |
} | |
}, [isLocked]) | |
} | |
export default useLockBodyScroll |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment