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

103
Vistas
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 Respuestas
Responde la pregunta

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 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