use-copy-to-clipboard
A hook that copies text and reports a transient copied state.
Installation
$ pnpm dlx shadcn@latest add @soultel/use-copy-to-clipboardNo namespace set up? npx shadcn@latest add https://asafefe.dev/r/use-copy-to-clipboard.json works too.
Manual installation
- 1. Copy the source from the Code tab into hooks/use-copy-to-clipboard.ts.
Usage
import { useCopyToClipboard } from "@/hooks/use-copy-to-clipboard"
export function Example() {
const { copied, copy } = useCopyToClipboard()
return <button onClick={() => copy("hello")}>{copied ? "Copied" : "Copy"}</button>
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| timeout | number | 2000 | How long `copied` stays true, in ms. |
