Merge branch 'main' into main
This commit is contained in:
commit
f36c649bb9
1 changed files with 118 additions and 66 deletions
29
client/src/lib/hooks/useCopy.ts
Normal file
29
client/src/lib/hooks/useCopy.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
type UseCopyProps = {
|
||||
timeout?: number;
|
||||
};
|
||||
|
||||
function useCopy({ timeout = 500 }: UseCopyProps = {}) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let timeoutId: NodeJS.Timeout;
|
||||
if (copied) {
|
||||
timeoutId = setTimeout(() => {
|
||||
setCopied(false);
|
||||
}, timeout);
|
||||
}
|
||||
return () => {
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
};
|
||||
}, [copied]);
|
||||
|
||||
return { copied, setCopied };
|
||||
}
|
||||
|
||||
export default useCopy;
|
||||
Loading…
Reference in a new issue