useClipboard is a custom hook that handles copying content to clipboard.
Arguments
The useClipboard hook takes the following arguments:
| Name | Type | Required | Description |
|---|---|---|---|
text | string | true | The text or value that is to be copied. |
optionsOrTimeout | number or object | false | The timeout as a number or an object containing 2 properties: timeout and format for the MIME type |
Return value
The useClipboard hook returns an object with the following fields:
| Name | Type | Default | Description |
|---|---|---|---|
value | string | The copied value. | |
onCopy | function | Callback function to copy content. | |
hasCopied | boolean | false | If true, the content has been copied. |
error | string | null | If set, contains an error message if the copy operation failed. |
clipboardPermission | string | null | The current clipboard permission state (granted, denied, or prompt). |
Import
import { useClipboard } from '@passfort/castle'content_copyCopy
Usage
content_copyCopy
live example