Skip to Content
⭐️ Leave a star →
HooksuseCopyToClipboard

useCopyToClipboard

Writes a string to the system clipboard and exposes a copied flag that auto-resets after resetAfter ms — perfect for “Copied!” UI affordances. Falls back to document.execCommand('copy') in non-secure contexts (e.g. plain HTTP, older browsers).

import { useCopyToClipboard } from '@wire-ui/react' function CopyButton({ text }: { text: string }) { const { copy, copied } = useCopyToClipboard({ resetAfter: 2000 }) return ( <button onClick={() => copy(text)} data-copied={copied}> {copied ? 'Copied!' : 'Copy'} </button> ) }

Options

OptionTypeDefaultDescription
resetAfternumber2000Milliseconds before copied resets to false. Pass 0 to disable auto-reset.

Returns

KeyTypeDescription
copy(text: string) => Promise<boolean>Write text to the clipboard. Resolves with true on success.
copiedbooleantrue for resetAfter ms after a successful copy.
valuestring | nullThe last text written, or null if nothing has been copied yet.
errorError | nullThe last copy error, if any.
reset() => voidClear copied, value, and error.
Last updated on

MIT License © 2026 wire-ui

useCopyToClipboard – Wire UI