9.4k

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

Return value

coss.com ui

Built by and for the team of Cal.com, Inc. — the leading commercial open source company (“coss”).