useClipboard

Hook for copying text to clipboard with a copied state indicator.

Usage

import { useClipboard } from "@spectre-ui/hooks";

function CopyButton({ text }) {
  const { copy, copied } = useClipboard(2000);

  return (
    <button onClick={() => copy(text)}>
      {copied ? "Copied!" : "Copy"}
    </button>
  );
}

Parameters

useClipboard(timeout?: number) // ms before copied resets (default: 2000)

Return Value

{
  copy: (text: string) => Promise<void>,
  copied: boolean,
}