From 8fe6cde592420448490db0fe70aea60a7ed7b97d Mon Sep 17 00:00:00 2001 From: JamesIntellijoint Date: Sun, 2 Jan 2022 12:31:14 -0500 Subject: [PATCH] Fix body scrolling --- src/App.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 6dc45ef..b0b77f5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -49,27 +49,26 @@ function App() { } } - function handleBodyScroll() { - if (showChapterMenu || showTranslationMenu || showMainMenu) { - document.body.style.overflow = "unset"; - } else { + const menuOpen = showChapterMenu || showTranslationMenu || showMainMenu; + + useEffect(() => { + if (menuOpen) { document.body.style.overflow = "hidden"; + } else { + document.body.style.overflow = "unset"; } - } + }, [showChapterMenu, showTranslationMenu, showMainMenu]); function showChapters() { setShowChapterMenu(!showChapterMenu); - handleBodyScroll(); } function showTranslations() { setShowTranslationMenu(!showTranslationMenu); - handleBodyScroll(); } function showMain() { setShowMainMenu(!showMainMenu); - handleBodyScroll(); } function selectThemeColor(newTheme: string) { @@ -108,7 +107,7 @@ function App() { return (
- {(showChapterMenu || showTranslationMenu || showMainMenu) && ( + {menuOpen && (
{