Created
January 6, 2021 15:46
-
-
Save jottenlips/7e1ef0e2ac253d3100b511c3bc94e129 to your computer and use it in GitHub Desktop.
react use-disable-body-scroll
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 { useEffect } from 'react'; | |
export const useDisableBodyScroll = (open) => { | |
useEffect(() => { | |
if (open) { | |
document.body.style.overflow = 'hidden'; | |
} else { | |
document.body.style.overflow = 'unset'; | |
} | |
}, [open]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment