useClipboard
Copies text to the system clipboard with automatic timeout reset and state feedback.
3.2 KB
•Updated on September 3, 2026
Example 2: Code Block with Copy Button
Example 3: Multi-Credential API Keys
Installation
Bash
pnpm dlx shadcn@latest add @spaceui/hooks-browser-use-clipboardUsage
Code
import { useClipboard } from '@/hooks/use-clipboard'
const { copy, copied } = useClipboard({ timeout: 2000 })
copy('Text to copy')API Reference
Parameters / Props
| Parameter | Type | Default | Description |
|---|---|---|---|
options.timeout | number | 2000 | Timeout in ms before copied resets. |
Return Value
| Property | Type | Description |
|---|---|---|
copy | (text: string) => Promise<boolean> | Triggers clipboard copy. |
copied | boolean | Whether text was recently copied. |
reset | () => void | Resets copied state immediately. |