Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
Debounce holding a key pressed (React)

is there a way to debounce holding a key (in React if it changes anything, I am aware that I need to wrap debounce in useCallback)?

I have a few selects, each of them sends request. There's a default possibility to hold tab to go through selects, so there are too many requests being sent.

Can I set debounce on holding tab key? Also I'd prefer a solution which doesn't affect a11y.

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I managed to hold the fetch by waiting a while, then checking if my select is the current document select, then fire the fetch or not

const sleep = (milliseconds = 500) => new Promise(resolve => setTimeout(resolve, milliseconds));

const handleFocus = async () => {
  await sleep();
  if (selectRef.current === document.activeElement) {
    if (!listShowed) {
      showList(true);
      document.addEventListener('click', hideList);
    }
    fetch();
  }
};

But needed to add ref. Not sure if it's the most optimal solution, but it works. If I change selected item rapidly, then after sleep() the selectRef.current !=== document.activeElement, so it won't fire

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda