File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 11'use client' ;
22
3- import { useState } from 'react' ;
3+ import { useEffect , useRef , useState } from 'react' ;
44import { Check , Clipboard } from 'react-feather' ;
55import * as Sentry from '@sentry/nextjs' ;
66
@@ -23,6 +23,15 @@ interface Props {
2323
2424export function CopyForLLMButton ( { markdownPath} : Props ) {
2525 const [ copied , setCopied ] = useState ( false ) ;
26+ const timeoutRef = useRef < NodeJS . Timeout | null > ( null ) ;
27+
28+ useEffect ( ( ) => {
29+ return ( ) => {
30+ if ( timeoutRef . current ) {
31+ clearTimeout ( timeoutRef . current ) ;
32+ }
33+ } ;
34+ } , [ ] ) ;
2635
2736 async function handleClick ( ) {
2837 let didCopy = false ;
@@ -51,7 +60,10 @@ export function CopyForLLMButton({markdownPath}: Props) {
5160 // Visual feedback only when something was actually copied
5261 if ( didCopy ) {
5362 setCopied ( true ) ;
54- setTimeout ( ( ) => setCopied ( false ) , 1200 ) ;
63+ if ( timeoutRef . current ) {
64+ clearTimeout ( timeoutRef . current ) ;
65+ }
66+ timeoutRef . current = setTimeout ( ( ) => setCopied ( false ) , 1200 ) ;
5567 }
5668 }
5769
You can’t perform that action at this time.
0 commit comments