From 119249384f8f7f4dab6a4c093c182b5dd12bb4f6 Mon Sep 17 00:00:00 2001 From: David Ichim Date: Fri, 12 Apr 2024 10:06:28 +0300 Subject: [PATCH] fix(inpage-navigation): warning Can't perform a React state update on an unmounted component --- src/ui/InpageNavigation/InpageNavigation.jsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ui/InpageNavigation/InpageNavigation.jsx b/src/ui/InpageNavigation/InpageNavigation.jsx index b32a6e35df..9b92ab603a 100644 --- a/src/ui/InpageNavigation/InpageNavigation.jsx +++ b/src/ui/InpageNavigation/InpageNavigation.jsx @@ -9,6 +9,10 @@ class InpageNavigation extends Component { scrollPosition: 0, removeClass: 'hidden', }; + this.debouncedHandleInpageNavigationVisibility = debounce( + this.handleInpageNavigationVisibility, + 250, + ); } handleInpageNavigationVisibility = () => { @@ -25,12 +29,16 @@ class InpageNavigation extends Component { componentDidMount() { window.addEventListener( 'scroll', - debounce(this.handleInpageNavigationVisibility, 250), + this.debouncedHandleInpageNavigationVisibility, ); } componentWillUnmount() { - window.removeEventListener('scroll', this.handleInpageNavigationVisibility); + window.removeEventListener( + 'scroll', + this.debouncedHandleInpageNavigationVisibility, + ); + this.debouncedHandleInpageNavigationVisibility.cancel(); } onInpageNavigationClick = () => {