fix: fixed copy to clipboard button (#8426)

Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
spc-28
2024-08-27 03:57:44 +05:30
committed by GitHub
parent afb68a6467
commit 26d2296578
12 changed files with 160 additions and 284 deletions

View File

@@ -0,0 +1,22 @@
import { useRef, useState } from "react";
const TIMEOUT = 2000;
export const useCopyStatus = () => {
const [copyStatus, setCopyStatus] = useState<"success" | null>(null);
const timeoutRef = useRef<number>(0);
const onCopy = () => {
clearTimeout(timeoutRef.current);
setCopyStatus("success");
timeoutRef.current = window.setTimeout(() => {
setCopyStatus(null);
}, TIMEOUT);
};
return {
copyStatus,
onCopy,
};
};