Appearance
useCopyToClipboard
Copies text to clipboard with toast feedback.
Signature
ts
function useCopyToClipboard(
options?: UseCopyToClipboardOptions
): UseCopyToClipboardReturnParameters
UseCopyToClipboardOptions
| Property | Type | Default | Description |
|---|---|---|---|
successMessage | string | 'Code copied!' | Toast message on success |
errorMessage | string | 'Unable to copy' | Toast message on error |
resetDelay | number | 2000 | Milliseconds before copied resets to false |
Return Type
UseCopyToClipboardReturn
| Property | Type | Description |
|---|---|---|
copy | (text: string) => Promise<boolean> | Copy text to clipboard |
copied | boolean | Whether text was recently copied |
error | Error | null | Error from last copy attempt |
Example
tsx
const { copy, copied } = useCopyToClipboard()
<Button onClick={() => copy('Hello!')}>
{copied ? 'Copied!' : 'Copy'}
</Button>