import { useState, useCallback } from 'react'; /** * Reusable hook for copy-to-clipboard with visual feedback. * * Returns a `copied` boolean (true for `resetDelay` ms after a successful * copy) and a `copy` async function. * * @example * ```tsx * const { copied, copy } = useCopyToClipboard(); * * * ``` */ export function useCopyToClipboard(resetDelay = 2000) { const [copied, setCopied] = useState(false); const copy = useCallback( async (text: string) => { try { await navigator.clipboard.writeText(text); setCopied(true); setTimeout(() => setCopied(false), resetDelay); return true; } catch { return false; } }, [resetDelay], ); return { copied, copy }; }