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

104
Visualizações
Debounce Function Empty TextField

I set up debounce inside my functional component like this:

const debouncedFunc= debounce(myFunction, 500);

I have the below TextField

    <TextField 
       id="myField" 
       maxLength={8}
       onChange={(e) => debouncedFunc(e.target?.value)} 
    />

I have the myFunction like this

  function myFunction(val) {
    if (val.length === 8) {
      console.log(val);
    }
  }

So this works well. It prints value when a user types eight characters into the field. The problem is that I need to empty the value in this field when a user types eight characters, and debounced function does kick in. Normally, TextField, I can empty the value in the field by e.target.value="". Since I am in the debounce function, I do not have a reference to the e, so I cannot empty it.

Long question short, what is the best way to empty the textfield from a debounce function?

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

0

My current and only solution is this, anyone that can think of a better solution please do share

export default function DebounceFeaturedTextfield() {
  const debouncedFunc= debounce(myFunction, 500);
  let TextFieldRef = "";
  function myFunction(val) {
    if (val.length === 8) {
      TextFieldRef.setInputValue("");
    }
  }
  return (
      <TextField 
      ref={(r) => {
        TextFieldRef = r;
      }}
       id="myField" 
       maxLength={8}
       onChange={(e) => debouncedFunc(e.target?.value)} 
    />
  );
}
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