(code: string, id: string)
| 7 | const [copiedId, setCopiedId] = useState<string | null>(null); |
| 8 | |
| 9 | const copyToClipboard = async (code: string, id: string) => { |
| 10 | try { |
| 11 | await navigator.clipboard.writeText(code); |
| 12 | setCopiedId(id); |
| 13 | toast.success("Code copied to clipboard!"); |
| 14 | setTimeout(() => setCopiedId(null), 1000); |
| 15 | } catch (error) { |
| 16 | console.error("Failed to copy to clipboard:", error); |
| 17 | toast.error("Failed to copy code"); |
| 18 | } |
| 19 | }; |
| 20 | |
| 21 | const isCopied = (id: string) => copiedId === id; |
| 22 |