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

NameDescription
copy(text)Async function that copies the given text.
copiedBoolean flag that becomes true briefly after a successful copy.

Example

const { copy, copied } = useClipboard();
await copy('hello'); // copied === true for ~1200ms

Notes

Graceful fallback uses a transient textarea element and document.execCommand('copy').
Saha UI - The Modern React Component Library