{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-copy-to-clipboard",
  "title": "useCopyToClipboard",
  "description": "Wraps the Clipboard API with a built-in timeout to reset the copied state, for copy buttons that show brief confirmation feedback.",
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/base/hooks/use-copy-to-clipboard.ts",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nexport function useCopyToClipboard({\n  timeout = 2000,\n  onCopy,\n}: {\n  timeout?: number\n  onCopy?: () => void\n} = {}): { copyToClipboard: (value: string) => void; isCopied: boolean } {\n  const [isCopied, setIsCopied] = React.useState(false)\n  const timeoutIdRef = React.useRef<NodeJS.Timeout | null>(null)\n\n  const copyToClipboard = (value: string): void => {\n    if (typeof window === \"undefined\" || !navigator.clipboard?.writeText) {\n      return\n    }\n\n    if (!value) return\n\n    navigator.clipboard.writeText(value).then(() => {\n      if (timeoutIdRef.current) {\n        clearTimeout(timeoutIdRef.current)\n      }\n\n      setIsCopied(true)\n\n      if (onCopy) {\n        onCopy()\n      }\n\n      if (timeout !== 0) {\n        timeoutIdRef.current = setTimeout(() => {\n          setIsCopied(false)\n          timeoutIdRef.current = null\n        }, timeout)\n      }\n    }, console.error)\n  }\n\n  // Cleanup timeout on unmount\n  React.useEffect(() => {\n    return (): void => {\n      if (timeoutIdRef.current) {\n        clearTimeout(timeoutIdRef.current)\n      }\n    }\n  }, [])\n\n  return { copyToClipboard, isCopied }\n}\n",
      "type": "registry:hook"
    }
  ],
  "type": "registry:hook"
}