From ec87ea8dd700db060a599afcbd0985c97fde4cb8 Mon Sep 17 00:00:00 2001 From: Marc Itzenthaler Date: Tue, 7 Dec 2021 11:47:09 +0000 Subject: [PATCH] fix: unset timeout after unmounting component to prevent reload --- src/components/button/Button.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/button/Button.tsx b/src/components/button/Button.tsx index a60f746c5..014dcc465 100644 --- a/src/components/button/Button.tsx +++ b/src/components/button/Button.tsx @@ -44,6 +44,10 @@ export const Button = (props: ButtonProps) => { useEffect(() => { handleButtonTimer(); + + return (): void => { + if (timeoutID) window.clearTimeout(timeoutID); + }; }, []); // eslint-disable-line react-hooks/exhaustive-deps const handleButtonTimer = () => { @@ -87,7 +91,7 @@ export const Button = (props: ButtonProps) => { } if (!props.disabled && !props.item.disabled && props.buttonHandle) { - window.clearTimeout(timeoutID); + if (timeoutID) window.clearTimeout(timeoutID); props.buttonHandle(item.function); } };