Hook

useClipboard

The useClipboard hook provides a simple way to copy text to the clipboard and track whether the operation completed successfully. It is ideal for copy buttons, invite links, code snippets, and shareable content.

Import
import { useClipboard } from "@shivms/ui";

API

The hook provides methods and state for copying text to the clipboard.

copy

Copies the provided text to the user's clipboard.

copied

Returns whether the copy operation was successful.

Reset

Automatically resets the copied state after a delay.

Basic Usage

Call the copy() function with the text you want to place on the clipboard.

import {
    Button,
    useClipboard,
} from "@shivms/ui";

export default function App() {
    const {
        copy,
        copied,
    } = useClipboard();

    return (
        <Button
            onClick={() => copy("Hello World")}
        >
            {copied
                ? "Copied!"
                : "Copy"}
        </Button>
    );
}

Features

01

Copy Text

Copy any string to the clipboard with a single function call.

02

Copy Status

Track whether the copy operation completed successfully.

03

User Friendly

Perfect for copy buttons, invite links, code snippets, and share actions.

Continue Reading

Explore more SHIVMS UI documentation and guides.