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

267
Visualizações
lodash debounce ignore space key

hi im working with lodash .. everything working so good .. but i have problem thats i want debouce not working when enter key is pressed .. and this is my lodash key ..

search_products:_.debounce(function(event)
{
     // my code here 
    // how can i let debounce work with all keys but not with enter key
},5),

i want the delay 5ml not working with enter also if there is any ather method like debouce or any anther library can anyone help me here is that possable thanks

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can extract the debounced function and only call it when something other than the enter key is pressed.

{
  search_products: function (event) {
    if (event.code !== 'Enter') {
      debounced(event);
    }
  }
}

const debounced = _.debounce(function(event) {
  // ...
}, 5);
about 4 years ago · Juan Pablo Isaza Relatório

0

You can use the flush() method included with lodash debounce

flush will immediately invoke all delayed function invocations.

Type below and there will be a 1 second delay, but hit enter and it will log the result immediately.

const debounced = _.debounce(value => {
  console.log(value);
}, 1000);

const handler = event => {
  if (event.key === 'Enter') return debounced.flush();

  debounced(event.target.value);
}

document.querySelector('input').addEventListener('keyup', handler);
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<input type="text" placeholder="type something">

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