useCopyToClipboard

Copy text to the clipboard with a success state that automatically resets.

import { useCopyToClipboard } from "@allem-sdk/hooks";

Returns

PropertyTypeDescription
copiedbooleanTrue for 2 seconds after a successful copy
copy(text: string) => Promise<void>Copy text to clipboard

Usage

const { copied, copy } = useCopyToClipboard();

<button onClick={() => copy("npm install allem-sdk")}>
  {copied ? "Copied!" : "Copy"}
</button>