MCPcopy Create free account
hub / github.com/AntiHub-Project/AntiHub / copyToClipboard

Function copyToClipboard

components/ai-elements/code-block.tsx:149–163  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

147 const { code } = useContext(CodeBlockContext);
148
149 const copyToClipboard = async () => {
150 if (typeof window === "undefined" || !navigator?.clipboard?.writeText) {
151 onError?.(new Error("Clipboard API not available"));
152 return;
153 }
154
155 try {
156 await navigator.clipboard.writeText(code);
157 setIsCopied(true);
158 onCopy?.();
159 setTimeout(() => setIsCopied(false), timeout);
160 } catch (error) {
161 onError?.(error as Error);
162 }
163 };
164
165 const Icon = isCopied ? CheckIcon : CopyIcon;
166

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected