Replug SAML configurations
Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
@@ -4,3 +4,4 @@ export { useRefSync } from "./useRefSync";
|
||||
export { useList } from "./useList";
|
||||
export { useStateWithRef } from "./useStateWithRef";
|
||||
export { useCleanup } from "./useCleanup";
|
||||
export { useCopy } from "./useCopy";
|
||||
|
||||
18
packages/hooks/src/useCopy.ts
Normal file
18
packages/hooks/src/useCopy.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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];
|
||||
}
|
||||
Reference in New Issue
Block a user