Utility
useClipboard
Copy text to clipboard with success feedback and error handling.
import { useClipboard } from "saha-ui"Uses
Copy text to the clipboard with a fallback for browsers that lack the modern API, and provide a temporary copied flag for UI feedback.
Returns
| Name | Description |
|---|---|
| copy(text) | Async function that copies the given text. |
| copied | Boolean flag that becomes true briefly after a successful copy. |
Example
const { copy, copied } = useClipboard();
await copy('hello'); // copied === true for ~1200msNotes
Graceful fallback uses a transient textarea element and document.execCommand('copy').