SSE Hooks

useCopyToClipboard

Custom hook that copies text to the clipboard using the Clipboard API.

Installation

npx sse-hooks add use-copy-to-clipboard

Usage

example.ts
import { useCopyToClipboard } from "./{hooks file}";

const [copiedText, copyToClipboard] = useCopyToClipboard();
const textToCopy = "Hello, world!";

// Attempt to copy text to the clipboard
copyToClipboard(textToCopy).then((success) => {
  if (success) {
    console.log(`Text "${textToCopy}" copied to clipboard successfully.`);
  } else {
    console.error("Failed to copy text to clipboard.");
  }
});

API

Parameters

Prop Default Type

Returns

Return Value Default Type
[0]-

string | null

[1]-

(text: string) => Promise<boolean>

Types Aliases

No specific type aliases defined for this component.

Changelog

c165d — feat: enhance useRoleGuard and useSSR hooks with additional options and documentation

30da4 — feat: add new hooks and their metadata

cf13e — feat: add custom hooks for step navigation, ternary dark mode, timeout, toggle, unmount, and window size

Built with Love • © 2026