MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / useCopyToClipboard

Function useCopyToClipboard

webview-ui/src/utils/clipboard.ts:34–75  ·  view source on GitHub ↗
(feedbackDuration = 2000)

Source from the content-addressed store, hash-verified

32 * React hook for managing clipboard copy state with feedback
33 */
34export const useCopyToClipboard = (feedbackDuration = 2000) => {
35 const [showCopyFeedback, setShowCopyFeedback] = useState(false)
36 const timeoutRef = useRef<NodeJS.Timeout | null>(null)
37
38 const copyWithFeedback = useCallback(
39 async (text: string, e?: React.MouseEvent) => {
40 e?.stopPropagation()
41
42 // Clear any existing timeout
43 if (timeoutRef.current) {
44 clearTimeout(timeoutRef.current)
45 }
46
47 const success = await copyToClipboard(text, {
48 onSuccess: () => {
49 setShowCopyFeedback(true)
50 timeoutRef.current = setTimeout(() => {
51 setShowCopyFeedback(false)
52 timeoutRef.current = null
53 }, feedbackDuration)
54 },
55 })
56
57 return success
58 },
59 [feedbackDuration],
60 )
61
62 // Cleanup timeout on unmount
63 useEffect(() => {
64 return () => {
65 if (timeoutRef.current) {
66 clearTimeout(timeoutRef.current)
67 }
68 }
69 }, [])
70
71 return {
72 showCopyFeedback,
73 copyWithFeedback,
74 }
75}

Callers 7

TaskActionsFunction · 0.90
Markdown.tsxFile · 0.90
ErrorRow.tsxFile · 0.90
MermaidBlockFunction · 0.90
MermaidButtonFunction · 0.90
CodeBlock.tsxFile · 0.90
ImageViewerFunction · 0.90

Calls 1

copyToClipboardFunction · 0.85

Tested by

no test coverage detected