fix copy button with useeffect

This commit is contained in:
2026-03-07 00:57:21 +01:00
parent 25d0865f89
commit 55e97a68f6
+8 -1
View File
@@ -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<typeof setTimeout>;
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 (