File size: 688 Bytes
55947a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { useState, useCallback } from 'react';

export function useCopy(timeout = 2000) {
  const [copied, setCopied] = useState(false);

  const copy = useCallback(
    async (text: string) => {
      if (!navigator.clipboard) {
        console.error('Clipboard API not available');
        return false;
      }
      
      try {
        await navigator.clipboard.writeText(text);
        setCopied(true);
        
        setTimeout(() => {
          setCopied(false);
        }, timeout);
        
        return true;
      } catch (error) {
        console.error('Failed to copy text:', error);
        return false;
      }
    },
    [timeout]
  );

  return { copied, copy };
}