Swirski UI

Hook

useClipboard

Copies text to the clipboard and tracks copied/error state.

Import

import { useClipboard } from "@swirski/ui";

Preview

Live render

useClipboard

Preview
Clipboard

Used by the docs copy buttons and handy for snippets.

Usage

const clipboard = useClipboard();

<Button onClick={() => clipboard.copy("pnpm add @swirski/ui")}>
  {clipboard.copied ? "Copied" : "Copy"}
</Button>

Props

1 documented
PropTypeDefaultNotes
options.timeoutnumber1600Copied-state reset delay in milliseconds.

Returns

4 documented
ValueTypeNotes
copiedbooleanTrue immediately after a successful copy.
copy(value: string) => Promise<void>Copies text to the clipboard.
errorError | nullLast copy error.
reset() => voidClears copied and error state.
Previous: useReducedMotionNext: usePortalRoot