Files
cal.diy/packages/lib/hooks/useCopy.ts
T
+27 10ffd9bacd feat: Org user table - bulk actions (#10504)
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Leo Giovanetti <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: zomars <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Keith Williams <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Syed Ali Shahbaz <[email protected]>
Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: Shivam Kalra <[email protected]>
Co-authored-by: cherish2003 <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
Co-authored-by: rkreddy99 <[email protected]>
Co-authored-by: varun thummar <Varun>
Co-authored-by: Crowdin Bot <[email protected]>
Co-authored-by: Pradumn Kumar <[email protected]>
Co-authored-by: Richard Poelderl <[email protected]>
Co-authored-by: mohammed hussam <[email protected]>
Co-authored-by: Carina Wollendorfer <[email protected]>
Co-authored-by: Anik Dhabal Babu <[email protected]>
Co-authored-by: nicktrn <[email protected]>
Co-authored-by: sydwardrae <[email protected]>
Co-authored-by: Janakiram Yellapu <[email protected]>
Co-authored-by: GitStart-Cal.com <[email protected]>
Co-authored-by: sajanlamsal <[email protected]>
Co-authored-by: Cherish <[email protected]>
Co-authored-by: Danila <[email protected]>
Co-authored-by: Neel Patel <[email protected]>
Co-authored-by: Rama Krishna Reddy <[email protected]>
Co-authored-by: Varun Thummar <[email protected]>
Co-authored-by: Bhargav <[email protected]>
Co-authored-by: Pratik Kumar <[email protected]>
Co-authored-by: Ritesh Patil <[email protected]>
2023-08-15 14:07:38 -07:00

28 lines
739 B
TypeScript

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 };
}