From 55e97a68f6ff25c9380334123fed9d6034c8197f Mon Sep 17 00:00:00 2001 From: skidoodle Date: Sat, 7 Mar 2026 00:57:21 +0100 Subject: [PATCH] fix copy button with useeffect --- components/CopyButton.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/CopyButton.tsx b/components/CopyButton.tsx index 369ee8b..e79ea88 100644 --- a/components/CopyButton.tsx +++ b/components/CopyButton.tsx @@ -3,12 +3,19 @@ import { CheckIcon, ClipboardDocumentIcon } from '@heroicons/react/24/outline'; export const CopyButton = ({ text }: { text: string }) => { const [copied, setCopied] = useState(false); + useEffect(() => { + let timeout: ReturnType; + if (copied) { + timeout = setTimeout(() => setCopied(false), 2000); + } + return () => clearTimeout(timeout); + }, [copied]); + const handleCopy = async (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); await navigator.clipboard.writeText(text); setCopied(true); - setTimeout(() => setCopied(false), 2000); }; return (