useClipboard
Copies text to clipboard and tracks success/error state.
Import
Section titled “Import”import { useClipboard } from 'asterui'function CopyExample() { const { copy, copied } = useClipboard()
return ( <Button onClick={() => copy('Hello, World!')}> {copied ? 'Copied!' : 'Copy to Clipboard'} </Button> )}Parameters
Section titled “Parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
timeout | number | 2000 | Duration in ms to show copied state |
Return Value
Section titled “Return Value”| Property | Type | Description |
|---|---|---|
copy | (text: string) => Promise<boolean> | Copies text, returns success status |
copied | boolean | True if recently copied successfully |
error | Error | null | Error if copy failed |
reset | () => void | Resets copied and error state |