WarningThe Clipboard API requires a Secure Context (HTTPS). On non-secure origins, navigator.clipboard will be undefined, and the hook will throw an error.
ImportantThis method must be called within a short delay after a user interaction (like a click event) to be permitted by the browser's security model.
This hook provides a robust way to interact with the navigator.clipboard API. It manages the state of the last copied text and handles environment checks to ensure the API is available before execution.
| Name | Type | Description |
|---|---|---|
| copyToClipboard | (text: string) => Promise<void> | Async function that writes the provided string to the clipboard. |
| textCopied | string | null | The last successfully copied string. Defaults to null. |