Skip to content

Commit

Permalink
fix: unset timeout after unmounting component to prevent reload
Browse files Browse the repository at this point in the history
  • Loading branch information
web-mi committed Dec 7, 2021
1 parent 4b25772 commit ec87ea8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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);
}
};
Expand Down

0 comments on commit ec87ea8

Please sign in to comment.