parent
e9c5b6907c
commit
2822509ff8
4 changed files with 48 additions and 30 deletions
@ -0,0 +1,22 @@ |
||||
import { useEffect, useState } from 'preact/hooks'; |
||||
|
||||
export function useIsCopied() { |
||||
const [isCopied, setIsCopied] = useState(false); |
||||
|
||||
const handleCopy = (text: string) => { |
||||
navigator.clipboard.writeText(text); |
||||
setIsCopied(true); |
||||
}; |
||||
|
||||
useEffect(() => { |
||||
let timeout: ReturnType<typeof setTimeout>; |
||||
if (isCopied) { |
||||
timeout = setTimeout(() => { |
||||
setIsCopied(false); |
||||
}, 2000); |
||||
} |
||||
return () => clearTimeout(timeout); |
||||
}, [isCopied]); |
||||
|
||||
return { isCopied, handleCopy }; |
||||
} |
Loading…
Reference in new issue