first commit
This commit is contained in:
27
calcom/packages/lib/hooks/useCopy.ts
Normal file
27
calcom/packages/lib/hooks/useCopy.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
export function useCopy() {
|
||||
const [isCopied, setIsCopied] = useState(false);
|
||||
|
||||
const copyToClipboard = (text: string) => {
|
||||
if (typeof navigator !== "undefined" && navigator.clipboard) {
|
||||
navigator.clipboard
|
||||
.writeText(text)
|
||||
.then(() => setIsCopied(true))
|
||||
.catch((error) => console.error("Copy to clipboard failed:", error));
|
||||
}
|
||||
};
|
||||
|
||||
const resetCopyStatus = () => {
|
||||
setIsCopied(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (isCopied) {
|
||||
const timer = setTimeout(resetCopyStatus, 3000); // Reset copy status after 3 seconds
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [isCopied]);
|
||||
|
||||
return { isCopied, copyToClipboard, resetCopyStatus };
|
||||
}
|
||||
Reference in New Issue
Block a user