← Components

use-copy-to-clipboard

hook

A hook that copies text and reports a transient copied state.

Installation

Namespace
npx shadcn@latest add @soultel/use-copy-to-clipboard
URL
npx shadcn@latest add https://asafefe.dev/r/use-copy-to-clipboard.json

Usage

usage.tsx
import { useCopyToClipboard } from "@/hooks/use-copy-to-clipboard"

export function Example() {
  const { copied, copy } = useCopyToClipboard()
  return <button onClick={() => copy("hello")}>{copied ? "Copied" : "Copy"}</button>
}