Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
clearTimeout dentro de un controlador de eventos

Estoy detectando un final de desplazamiento con clearTimeout.

 const Component= ({container}) => { const timeoutRef = useRef<number>(0) const handleScroll = { clearTimeout(timeoutRef.current) timeoutRef.current = setTimeout(function () { if(!timeoutRef.current){ // 'no scroll in progress, do something' } }, 100) } useEffect(() => { container.addEventListener('scroll', handleScroll, true) }, []) }

Pero el timeoutRef no se restablece cuando se vuelve a desplazar, sino que su valor solo aumenta. ¿Cómo arreglar eso?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Así es como funciona setTimeout. Cada vez que genera un tiempo de espera, genera un nuevo identificador. Utiliza ese identificador para cancelar el tiempo de espera. El tiempo de espera no borra la variable.

Si se dispara setTimeout, eso significa que no se canceló. En su caso, eso significa que el usuario dejó de desplazarse.

 timeoutRef.current = setTimeout(function () { console.log('User is done scrolling'); }, 100)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!