useCopyToClipboard
A small hook that copies text and tracks the latest copy result.
Ready to copy.
Installation
npx shadcn@latest add https://underscore-cn.vercel.app/r/use-copy-to-clipboard.jsonUsage
Call copy with the text you want to place on the clipboard. The hook exposes the latest copy
status so your UI can respond after the operation completes.
import { useCopyToClipboard } from "@/hooks/use-copy-to-clipboard";
export function CopyButton() {
const copyState = useCopyToClipboard();
return (
<button onClick={() => void copyState.copy("Copied from my app")}>
{copyState.status === "copied" ? "Copied" : "Copy"}
</button>
);
}