Skip to content

useClipboard

@astryxdesign/core v0.7.1 · useClipboard

Parameters ​

NameTypeDefaultDescription
optionsUseClipboardOptions{}Configuration object. Optional.
options.announcestring—Message announced to a polite live region on a successful copy. A swapped aria-label alone is not reliably announced, so pass the localized confirmation (e.g. "Copied") to have it spoken. Omit to skip the announcement.
options.resetAfterMsnumber2000Milliseconds isCopied stays true after a successful copy before reverting.

Returns ​

NameTypeDescription
copy(text: string) => Promise<boolean>Writes text to the clipboard. On success flips isCopied to true, announces the configured message, restarts the reset timer, and resolves true. A clipboard rejection is a silent no-op that leaves the copied state unchanged and resolves false.
isCopiedRef<boolean>True for resetAfterMs after the most recent successful copy, then reverts. Drive the copied confirmation (e.g. a copy → check icon flip) off this.