seam useCopy
useCopy is a headless React hook that copies text to the clipboard and exposes a `copied` flag that automatically resets after a configurable delay (default 2000 ms). It is the shared engine behind seamui's code block, terminal block, and branch chip copy buttons.
Installation
Requires @seamui in the registries of your components.json (shadcn adds official directory namespaces automatically).
Usage
import { useCopy } from "@/lib/use-copy"export function CopyButton({ text }: { text: string }) { const { copied, copy } = useCopy() return ( <button type="button" onClick={() => copy(text)}> {copied ? "Copied" : "Copy"} </button> )}- Add a copy-to-clipboard button where the label or icon should briefly show a success state (e.g. "Copied") and then reset.
- Share one consistent copy behavior across code blocks, terminal snippets, invite links, or branch names in the same app.
- Use it when you need the copy result as a boolean (true on success, false when the clipboard is unavailable) to show a fallback message.
- Prefer it over calling navigator.clipboard directly when you want rapid re-clicks and unmounts handled safely without manual timer cleanup.
Examples
Basic copy button
A button that copies a string and shows "Copied" for two seconds using the default reset delay.
import { Button } from "@/components/ui/button"import { useCopy } from "@/lib/use-copy"export function CopyButton({ text }: { text: string }) { const { copied, copy } = useCopy() return ( <Button variant="outline" size="sm" onClick={() => copy(text)}> {copied ? "Copied" : "Copy"} </Button> )}Custom reset delay with failure fallback
Uses a 1500 ms reset delay and reports failure when the copy resolves to false, for example in an insecure context.
import * as React from "react"import { useCopy } from "@/lib/use-copy"export function InviteLink({ url }: { url: string }) { const { copied, copy } = useCopy(1500) const [failed, setFailed] = React.useState(false) return ( <div> <code>{url}</code> <button type="button" onClick={async () => setFailed(!(await copy(url)))}> {copied ? "Copied" : failed ? "Failed" : "Copy link"} </button> </div> )}Compact branch chip
An icon-free chip that copies a branch name and shows a check mark after a successful copy, with an accessible label.
import { useCopy } from "@/lib/use-copy"export function BranchChip({ branch }: { branch: string }) { const { copied, copy } = useCopy() return ( <button type="button" aria-label={`Copy branch ${branch}`} onClick={() => copy(branch)}> {branch} {copied ? "✓" : ""} </button> )}API reference
Accessibility
- The hook changes no DOM and sets no ARIA attributes, so accessibility depends on the element that calls copy().
- Make the success state perceivable beyond color or a visual check mark. Put the copied state in the button's visible text ("Copied") or announce it with an aria-live region, since screen readers may not notice a label change on their own.
- When the icon or label is the only content, provide an aria-label that describes the action and target, such as "Copy branch main".
- Handle the false return value of copy() to tell users when copying failed, for example in insecure contexts where navigator.clipboard is unavailable.
- The hook clears its pending reset timer on unmount and before each new copy, so the flag does not update after the component is gone.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "seam useCopy" component (seamui/use-copy) from its shadcn registry.1. Install it with: npx shadcn@latest add @seamui/use-copy2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: resetAfter.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { useCopy } from "@/lib/use-copy"export function CopyButton({ text }: { text: string }) { const { copied, copy } = useCopy() return ( <button type="button" onClick={() => copy(text)}> {copied ? "Copied" : "Copy"} </button> )}```Files & dependencies
- registry/seam/lib/use-copy.ts→ lib/use-copy.ts
Looks similar, elsewhere
There is no screenshot of this item to compare yet.