Files
probo/packages/hooks/src/useCopy.ts
Émile Ré b012b5ec42 Replug SAML configurations
Signed-off-by: Émile Ré <nemile.re@gmail.com>
2026-01-17 10:25:17 -08:00

19 lines
552 B
TypeScript

import { useRef, useState } from "react";
export function useCopy(): [boolean, (value: string) => void] {
const [copiedValue, setCopiedValue] = useState<string>();
const lastCopiedValueRef = useRef<string>("");
const handleCopy = (value: string) => {
lastCopiedValueRef.current = value;
navigator.clipboard.writeText(value);
setCopiedValue(value);
setTimeout(() => {
setCopiedValue(undefined);
lastCopiedValueRef.current = "";
}, 2000);
};
return [copiedValue === lastCopiedValueRef.current, handleCopy];
}