Skip to content

Commit

Permalink
fix: clear timeout within useEffect hook
Browse files Browse the repository at this point in the history
Signed-off-by: abhijithvijayan <[email protected]>
  • Loading branch information
abhijithvijayan committed Apr 4, 2021
1 parent 8857890 commit 84f4af6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion source/History/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion source/Popup/ResponseBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 84f4af6

Please sign in to comment.