Skip to content

Commit

Permalink
fix(BackToTop): fix null exception on load (#9665)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrances17 authored Oct 9, 2023
1 parent 8475a6d commit d02b802
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/react-core/src/components/BackToTop/BackToTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ const BackToTopBase: React.FunctionComponent<BackToTopProps> = ({
const [scrollElement, setScrollElement] = React.useState(null);

const toggleVisible = () => {

Check warning on line 36 in packages/react-core/src/components/BackToTop/BackToTop.tsx

View workflow job for this annotation

GitHub Actions / lint

The 'toggleVisible' function makes the dependencies of useEffect Hook (at line 74) change on every render. Move it inside the useEffect callback. Alternatively, wrap the definition of 'toggleVisible' in its own useCallback() Hook
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);
}
}
}
};
Expand Down

0 comments on commit d02b802

Please sign in to comment.