NeoTerm UI

useCopyToClipboard

Copy text to clipboard with a brief 'copied' flash state.

Import

import { useCopyToClipboard } from "neoterm-ui";

Usage

const { copied, copy } = useCopyToClipboard();

<Button onClick={() => copy("npm install neoterm-ui")}>
  {copied ? "Copied!" : "Copy"}
</Button>

Signature

function useCopyToClipboard(resetMs?: number): {
  copied: boolean;
  copy: (text: string) => Promise<void>;
}

Parameters

PropTypeDefaultDescription
resetMsnumber2000Time in ms before copied resets to false.