Documentation Index
Fetch the complete documentation index at: https://mintlify.com/rijvi-mahmud/shaddy/llms.txt
Use this file to discover all available pages before exploring further.
useClipboardCopy is a React hook that wraps the browser’s navigator.clipboard.writeText API and exposes a clean, typed interface for copying text to the clipboard. It tracks what was last copied and the current copy status (idle, success, or error), so you can easily update your UI — for example, swapping a “Copy” label for a “Copied!” confirmation — without managing that state yourself. The status automatically resets to idle after two seconds.
Installation
Signature
Parameters
useClipboardCopy takes no parameters.
Return Value
The hook returns a three-element tuple.The text that was most recently copied successfully.
null when nothing has been copied yet or when the last copy attempt failed.An async function that writes the provided string to the clipboard. Returns
true on success and false when the clipboard API is unavailable or the operation fails.The current state of the copy operation.
'idle'— no copy has been attempted yet, or the status has reset after a previous attempt.'success'— the last copy succeeded.'error'— the last copy failed (for example, because clipboard access was denied).
Usage
Checking the Return Value
Notes
- The
copyfunction is memoised withuseCallbackand has a stable reference across renders, so it is safe to pass as a prop or include in a dependency array. - The hook logs a warning to the console when
navigator.clipboardis not available (for example, in non-HTTPS contexts) or when an empty string is passed. - The
copyStatusautomatically resets to'idle'two seconds after a'success'or'error'result, so transient UI feedback disappears without any extra work on your side. - Clipboard access requires a secure context (HTTPS or
localhost). In HTTP environments thecopyfunction returnsfalseand logs a warning.