Documentation Index
Fetch the complete documentation index at: https://mintlify.com/kokonut-labs/kokonutui/llms.txt
Use this file to discover all available pages before exploring further.
A React hook that provides an easy way to copy text to the clipboard with automatic state management for showing copy feedback.
Installation
This hook can be installed via the CLI:- Tab Title
- Tab Title
- Tab Title
bunx --bun shadcn@latest add @kokonutui/use-copy-to-clipboard
/hooks/use-copy-to-clipboard.ts into your project.
Usage
API Reference
Parameters
The hook accepts an optional configuration object:| Parameter | Type | Default | Description |
|---|---|---|---|
timeout | number | 2000 | Duration in milliseconds before isCopied resets to false |
onCopy | () => void | undefined | Optional callback function to execute after successful copy |
Return Value
Returns an object with:| Property | Type | Description |
|---|---|---|
isCopied | boolean | Whether text was recently copied (true during timeout period) |
copyToClipboard | (value: string) => void | Function to copy text to clipboard |
Features
- Automatic state management -
isCopiedautomatically resets after timeout - Custom timeout - Configure how long the copied state persists
- Callback support - Execute custom logic after copying
- Browser compatibility check - Safely handles environments without clipboard API
Example with Custom Timeout
Use Cases
- Copy buttons for code blocks
- Share link functionality
- Copy API keys or tokens
- Copy formatted text or JSON
- Copy-to-clipboard for contact information
Notes
- Requires modern browser with Clipboard API support
- Only works in secure contexts (HTTPS or localhost)
- Automatically handles server-side rendering (no errors)