File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change 1
- import { useState } from 'react'
1
+ import { useRef , useState } from 'react'
2
2
import { useCopyToClipboard } from 'react-use'
3
3
4
4
export function useCopy ( ) {
5
5
const [ state , copyToClipboard ] = useCopyToClipboard ( )
6
6
7
7
const [ copied , setCopied ] = useState ( false )
8
8
9
+ const timeoutRef = useRef < number | null > ( null )
10
+
9
11
function copyText ( text : string ) {
12
+ setCopied ( false )
13
+
14
+ if ( timeoutRef . current ) {
15
+ clearTimeout ( timeoutRef . current )
16
+ }
17
+
10
18
copyToClipboard ( text )
11
19
12
20
if ( state . value === text ) {
13
21
setCopied ( true )
14
22
15
- setTimeout ( ( ) => {
23
+ timeoutRef . current = window . setTimeout ( ( ) => {
16
24
setCopied ( false )
17
25
} , 2000 )
18
26
}
Original file line number Diff line number Diff line change @@ -329,9 +329,9 @@ export function TwoFactorRecoveryCodesDialog({ show }: { show?: boolean }) {
329
329
}
330
330
} , [ show ] )
331
331
332
- async function handleCopyClick ( ) {
332
+ function handleCopyClick ( ) {
333
333
if ( recoveryCodes ) {
334
- await copyText ( recoveryCodes . join ( '\n' ) )
334
+ copyText ( recoveryCodes . join ( '\n' ) )
335
335
}
336
336
}
337
337
You can’t perform that action at this time.
0 commit comments