From 3a9b0c81e27021ba40fbcc9eab45d3ea23ccb3d0 Mon Sep 17 00:00:00 2001 From: Shanmughapriyan S Date: Tue, 4 Oct 2022 06:36:09 +0530 Subject: [PATCH] [beta] fix: cleanup resize listener (#4847) --- beta/src/components/MDX/Challenges/Navigation.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beta/src/components/MDX/Challenges/Navigation.tsx b/beta/src/components/MDX/Challenges/Navigation.tsx index 51cf5cb52..e448828cf 100644 --- a/beta/src/components/MDX/Challenges/Navigation.tsx +++ b/beta/src/components/MDX/Challenges/Navigation.tsx @@ -71,9 +71,10 @@ export function Navigation({ useEffect(() => { handleResize(); - window.addEventListener('resize', debounce(handleResize, 200)); + const debouncedHandleResize = debounce(handleResize, 200); + window.addEventListener('resize', debouncedHandleResize); return () => { - window.removeEventListener('resize', handleResize); + window.removeEventListener('resize', debouncedHandleResize); }; }, [handleResize]);