Browser APIs
useClipboard
About
React hook for reading from and writing to the system clipboard using the Clipboard API.
Installation
Usage
Return Value
Returns an object with the following properties:
| Property | Type | Description |
|---|---|---|
| text | string | null | The current text content from the clipboard |
| copy | (value: string) => Promise<void> | Copy text to the clipboard |
| paste | () => Promise<void> | Read text from the clipboard |
| isSupported | boolean | Whether the Clipboard API is supported |
| error | Error | null | Any error that occurred during clipboard operations |
Features
- Copy text to clipboard - Write text using the Clipboard API
- Read from clipboard - Read text from the system clipboard
- Error handling - Comprehensive error handling for permission issues
- Browser support detection - Detects if Clipboard API is available
- TypeScript support - Full type definitions included
Browser Support
The Clipboard API requires:
- HTTPS context (or localhost for development)
- User permission for clipboard access
- Modern browsers (Chrome 66+, Firefox 63+, Safari 13.1+, Edge 79+)
Notes
- The clipboard read operation requires user permission in most browsers
- Some browsers may show a permission prompt when accessing the clipboard
- The hook automatically handles errors and permission denials
- Works only in secure contexts (HTTPS or localhost)