()
| 14 | }; |
| 15 | |
| 16 | export default function useCopy() { |
| 17 | const [copied, setCopied] = useState(false); |
| 18 | |
| 19 | const copyText = useCallback(async (text?: string) => { |
| 20 | const success = await copyToClipboard(text); |
| 21 | setCopied(success); |
| 22 | }, []); |
| 23 | |
| 24 | useEffect(() => { |
| 25 | if (!copied) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | const timerId = setTimeout(() => setCopied(false), 3000); |
| 30 | return () => clearTimeout(timerId); |
| 31 | }, [copied]); |
| 32 | |
| 33 | return [copied, copyText] as const; |
| 34 | } |