From 84f4af61f0a3f5b1db8398d13cbc39542a9986f1 Mon Sep 17 00:00:00 2001 From: abhijithvijayan <34790378+abhijithvijayan@users.noreply.github.com> Date: Sun, 4 Apr 2021 12:41:54 +0530 Subject: [PATCH] fix: clear timeout within useEffect hook Signed-off-by: abhijithvijayan <34790378+abhijithvijayan@users.noreply.github.com> --- source/History/Table.tsx | 10 +++++++++- source/Popup/ResponseBody.tsx | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/source/History/Table.tsx b/source/History/Table.tsx index 6f54b5b..e025f55 100644 --- a/source/History/Table.tsx +++ b/source/History/Table.tsx @@ -43,10 +43,18 @@ const Table: React.FC = () => { // reset copy message useEffect(() => { - setTimeout(() => { + let timer: NodeJS.Timeout | null = null; + + timer = setTimeout(() => { setCopied(false); // reset selected id from context }, 1300); + + return (): void => { + if (timer) { + clearTimeout(timer); + } + }; }, [copied]); function handleCopyToClipboard(selectedItemId: string): void { diff --git a/source/Popup/ResponseBody.tsx b/source/Popup/ResponseBody.tsx index a101058..74e8e9a 100644 --- a/source/Popup/ResponseBody.tsx +++ b/source/Popup/ResponseBody.tsx @@ -38,9 +38,17 @@ const ResponseBody: React.FC = () => { // reset copy message useEffect(() => { - setTimeout(() => { + let timer: NodeJS.Timeout | null = null; + + timer = setTimeout(() => { setCopied(false); }, 1300); + + return (): void => { + if (timer) { + clearTimeout(timer); + } + }; }, [copied]); return (