0
Documentation

useCopyToClipboard

Copy text to clipboard with a temporary "copied" state.

A React hook that wraps the Clipboard API with a built-in timeout to reset the copied state. Useful for copy buttons that show brief confirmation feedback.

Installation

Usage

Basic

Custom timeout

The isCopied state resets after 2 seconds by default. You can change this:

Set timeout to 0 to keep isCopied as true indefinitely (until the component unmounts).

Callback on copy

Run a side effect when a copy succeeds:

With icon swap

A common pattern — swap the icon briefly to confirm the copy:

API

Options

PropertyTypeDefaultDescription
timeoutnumber2000Milliseconds before isCopied resets to false. Set to 0 to keep it true.
onCopy() => void—Callback fired after a successful copy.

Return value

PropertyTypeDescription
copyToClipboard(value: string) => voidCall with the text to copy. No-op if value is empty or clipboard API is unavailable.
isCopiedbooleantrue for timeout ms after a successful copy, then resets.

© taut ui — built with Base UI and Tailwind CSS v4.