Skip to Content
OpenPerf

Hooks

useCopy

Returns a function that writes text to the clipboard and then shows a toast with the title and description you pass.

import { Button, useCopy } from "@openperf/deft";

const copy = useCopy();

<Button.Root onClick={() => copy(traceId, { title: "Trace ID copied", description: traceId })}>
  Copy trace ID
</Button.Root>;

Behaviour

AspectDetails
ProviderThe toast is rendered by Toast.Provider from the root providers. Without it the text is still copied, but no toast appears.
Timingcopy starts the clipboard write and returns right away. The toast is added when the write settles.
ToastHas no type, so it shows the success icon. It closes after the provider timeout, 5000 ms by default.
StackingThe provider shows at most three toasts at a time, so repeated copies stack up to that limit.

Failures are not reported

copy does not check the result of the write. If the browser has no Clipboard API or rejects the write, a warning is logged to the console and the toast is still shown.

API

useCopy takes no arguments and returns copy(text, params), which returns nothing.

Prop

Type

On this page