MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / useCopy

Function useCopy

packages/ui-components/src/hooks/useCopy.ts:16–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14};
15
16export 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}

Callers 2

BaseCodeBoxFunction · 0.85
TestComponentFunction · 0.85

Calls 1

copyToClipboardFunction · 0.85

Tested by 1

TestComponentFunction · 0.68