A React hook that copies text to the clipboard and tracks a temporary copied state for showing feedback.
"use client"; import { useClipboard } from "@/components/ui/use-clipboard"; export default function UseClipboardDemo() { const { copy, copied } = useClipboard(); return ( <div className="flex min-h-52 items-center justify-center"> <button type="button" onClick={() => copy("https://intentui.com")} className="inline-flex items-center gap-2 rounded-md border border-border bg-background px-4 py-2 text-sm font-medium text-foreground shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground" > {copied ? "Copied!" : "Copy link"} </button> </div> ); }
Part of Intent UI — browse the full library on 21st.dev.