chenzhaoyang
2025-12-17 063da0bf961e1d35e25dc107f883f7492f4c5a7c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { useCallback, useState } from "react";
import { copyText, isDefined } from "../utils/helpers";
 
export const useCopyText = ({ defaultText = "", timeout = 1200 }) => {
  const [copied, setCopied] = useState(false);
 
  const copyTextCallback = useCallback(
    (text?) => {
      setCopied(true);
      copyText(isDefined(text) ? text : defaultText);
      setTimeout(() => setCopied(false), timeout);
    },
    [defaultText, timeout],
  );
 
  return [copied, copyTextCallback];
};