({ timeout = 500 }: UseCopyProps = {})
| 7 | }; |
| 8 | |
| 9 | function useCopy({ timeout = 500 }: UseCopyProps = {}) { |
| 10 | const [copied, setCopied] = useState(false); |
| 11 | |
| 12 | useEffect(() => { |
| 13 | let timeoutId: NodeJS.Timeout; |
| 14 | if (copied) { |
| 15 | timeoutId = setTimeout(() => { |
| 16 | setCopied(false); |
| 17 | }, timeout); |
| 18 | } |
| 19 | return () => { |
| 20 | if (timeoutId) { |
| 21 | clearTimeout(timeoutId); |
| 22 | } |
| 23 | }; |
| 24 | }, [copied, timeout]); |
| 25 | |
| 26 | return { copied, setCopied }; |
| 27 | } |
| 28 | |
| 29 | export default useCopy; |
no outgoing calls
no test coverage detected