Skip to content

Files

Latest commit

 

History

History
38 lines (26 loc) · 734 Bytes

useCopyToClipboard.md

File metadata and controls

38 lines (26 loc) · 734 Bytes

useCopyToClipboard

Arguments

  • None

Returns

  • An array containing:
    • A function to copy text to the clipboard.
    • A boolean indicating if the copy was successful.

Hooks Involved

Liraries Involved

  • copy from copy-to-clipboard

How to Use

import useCopyToClipboard from "./useCopyToClipboard"

export default function CopyToClipboardComponent() {
    const [copyToClipboard, { success }] = useCopyToClipboard()

    return (
        <>
            <button onClick={() => copyToClipboard("This was copied")}>
                {success ? "Copied" : "Copy Text"}
            </button>
            <input type="text" />
        </>
    )
}