From d3014c88d796f58e70f7a778c67a709c6d0b0872 Mon Sep 17 00:00:00 2001 From: mfrances Date: Mon, 25 Sep 2023 09:47:58 -0400 Subject: [PATCH] fix(BackToTop): fix null exception on load --- .../src/components/BackToTop/BackToTop.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/react-core/src/components/BackToTop/BackToTop.tsx b/packages/react-core/src/components/BackToTop/BackToTop.tsx index 48d82742a41..2651bc6731f 100644 --- a/packages/react-core/src/components/BackToTop/BackToTop.tsx +++ b/packages/react-core/src/components/BackToTop/BackToTop.tsx @@ -34,12 +34,14 @@ const BackToTopBase: React.FunctionComponent = ({ const [scrollElement, setScrollElement] = React.useState(null); const toggleVisible = () => { - const scrolled = scrollElement.scrollY ? scrollElement.scrollY : scrollElement.scrollTop; - if (!isAlwaysVisible) { - if (scrolled > 400) { - setVisible(true); - } else { - setVisible(false); + if (scrollElement) { + const scrolled = scrollElement.scrollY ? scrollElement.scrollY : scrollElement.scrollTop; + if (!isAlwaysVisible) { + if (scrolled > 400) { + setVisible(true); + } else { + setVisible(false); + } } } };