computer-scienceangular-roadmapbackend-roadmapblockchain-roadmapdba-roadmapdeveloper-roadmapdevops-roadmapfrontend-roadmapgo-roadmaphactoberfestjava-roadmapjavascript-roadmapnodejs-roadmappython-roadmapqa-roadmapreact-roadmaproadmapstudy-planvue-roadmapweb3-roadmap
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
513 B
22 lines
513 B
import { useEffect, useState } from 'react'; |
|
|
|
export function useCopyText() { |
|
const [isCopied, setIsCopied] = useState(false); |
|
|
|
const copyText = (text: string) => { |
|
navigator.clipboard.writeText(text).then(); |
|
setIsCopied(true); |
|
}; |
|
|
|
useEffect(() => { |
|
let timeout: ReturnType<typeof setTimeout>; |
|
if (isCopied) { |
|
timeout = setTimeout(() => { |
|
setIsCopied(false); |
|
}, 2000); |
|
} |
|
return () => clearTimeout(timeout); |
|
}, [isCopied]); |
|
|
|
return { isCopied, copyText }; |
|
}
|
|
|