Registry Index

Search the catalog

Type to search items across every indexed registry, or pick a page.

HookOtherregistry:hookSelf-contained

Use Copy To Clipboard

use-copy-to-clipboard

Copy text to the clipboard with a temporary copied state.

hooks/use-copy-to-clipboard.ts
30 lines
"use client";

import { useState } from "react";

export type UseCopyToClipboardOptions = {
  copiedDuration?: number;
};

export const useCopyToClipboard = ({
  copiedDuration = 3000,
}: UseCopyToClipboardOptions = {}) => {
  const [isCopied, setIsCopied] = useState<boolean>(false);

  const copyToClipboard = (value: string) => {
    if (!value || typeof navigator === "undefined" || !navigator.clipboard) {
      return;
    }

    navigator.clipboard.writeText(value).then(
      () => {
        setIsCopied(true);
        setTimeout(() => setIsCopied(false), copiedDuration);
      },
      () => {},
    );
  };

  return { isCopied, copyToClipboard };
};
Used by 1 item

Built on Use Copy To Clipboard

Other @assistant-ui items that list this one as a dependency.

@assistant-ui

More from @assistant-ui

One call failed. The error, the attempt count, and a retry that doesn't restart the turn.

Find inside a long thread, with every hit marked down the scrollbar.

Granting a capability rather than approving one action, with the reach spelled out.

A whole working session summarized as verbs, targets, and file stats.

A small comparison table the model can answer with directly.

How much is left, when it comes back, and the way to get more.

The classic three dots, tuned to read as presence rather than noise.

A drawn answer with zoom, reset, and a full-bleed view; you hand it the rendered graphic.