From d02b802e6a22fde48b00bca98550cefe6ec88603 Mon Sep 17 00:00:00 2001 From: Mark Franceschelli <39063664+mfrances17@users.noreply.github.com> Date: Mon, 9 Oct 2023 10:17:48 -0400 Subject: [PATCH] fix(BackToTop): fix null exception on load (#9665) --- .../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); + } } } };