From 6ca592458e6eae4f5dc767ab93d42b19a27376dd Mon Sep 17 00:00:00 2001 From: LeBalz Date: Tue, 26 Nov 2024 23:44:22 +0100 Subject: [PATCH] cancel debounced functions on unmount --- src/components/documents/Excalidoc/Editor/index.tsx | 1 + src/hooks/useIsMobileView.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/components/documents/Excalidoc/Editor/index.tsx b/src/components/documents/Excalidoc/Editor/index.tsx index 98b94fb2..348b592a 100644 --- a/src/components/documents/Excalidoc/Editor/index.tsx +++ b/src/components/documents/Excalidoc/Editor/index.tsx @@ -96,6 +96,7 @@ const Editor = observer((props: Props) => { }, 50); document.addEventListener('scroll', onscroll); return () => { + onscroll.cancel(); document.removeEventListener('scroll', onscroll); }; }, [excalidrawAPI]); diff --git a/src/hooks/useIsMobileView.ts b/src/hooks/useIsMobileView.ts index f6c2a053..d5852a47 100644 --- a/src/hooks/useIsMobileView.ts +++ b/src/hooks/useIsMobileView.ts @@ -13,6 +13,7 @@ const useIsMobileView = (mobileViewWidth: number = 768) => { handleResize(); // Initial check return () => { + handleResize.cancel(); window.removeEventListener('resize', handleResize); }; }, [mobileViewWidth]);