From dd71508f2e18c021d7114d6bc540df595e37f509 Mon Sep 17 00:00:00 2001 From: gitstart Date: Mon, 17 Oct 2022 04:13:05 +0000 Subject: [PATCH] fix: conditional hook rule --- .../to-be-cleaned/SqlEditor/TabSqlQuery.js | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js b/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js index 82973f2cfee..3663daf9d33 100644 --- a/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js +++ b/studio/components/to-be-cleaned/SqlEditor/TabSqlQuery.js @@ -323,6 +323,22 @@ const Results = ({ results }) => { ['INPUT', 'TEXTAREA'] ) + useEffect(() => { + let timeoutId = 0 + + if (copiedCell) { + timeoutId = setTimeout(() => { + setCopiedCell(undefined) + }, 1000) + } + + return () => { + // we need to clear previous timeout to prevent checkmark flickering + // when clicking `Copy` btn multiple times in a short time + timeoutId && clearTimeout(timeoutId) + } + }, [copiedCell]) + if (results?.error) { return (
@@ -338,20 +354,6 @@ const Results = ({ results }) => { ) } - useEffect(() => { - let timeoutId = 0 - - if (copiedCell) { - timeoutId = setTimeout(() => { - setCopiedCell(undefined) - }, 1000) - } - - return () => { - timeoutId && clearTimeout(timeoutId) - } - }, [copiedCell]) - const handleCopyClick = (column, row, rowIndex) => { copyToClipboard(formatClipboardValue(row[column]), () => { setCopiedCell(`${column},${rowIndex}`)