Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda