{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-copy-to-clipboard",
  "title": "useCopyToClipboard",
  "description": "Copies text to the clipboard and tracks the copied state.",
  "files": [
    {
      "path": "hooks/use-copy-to-clipboard.ts",
      "content": "import * as React from \"react\";\n\nfunction useCopyToClipboard({ timeout = 2000 }: { timeout?: number } = {}) {\n  const [isCopied, setIsCopied] = React.useState(false);\n  const timeoutRef = React.useRef<ReturnType<typeof setTimeout>>(undefined);\n\n  React.useEffect(() => () => clearTimeout(timeoutRef.current), []);\n\n  const copy = React.useCallback(\n    async (value: string) => {\n      try {\n        await navigator.clipboard.writeText(value);\n      } catch {\n        return false;\n      }\n\n      setIsCopied(true);\n      clearTimeout(timeoutRef.current);\n      timeoutRef.current = setTimeout(() => setIsCopied(false), timeout);\n      return true;\n    },\n    [timeout],\n  );\n\n  return { copy, isCopied };\n}\n\nexport { useCopyToClipboard };\n",
      "type": "registry:hook"
    }
  ],
  "type": "registry:hook"
}