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

111
Visualizações
How to validate TextField with delay?

I'd like to highlight EMAIL TextField as invalid not immediately but after 5 seconds user starts to type in. So user types then stops then after 5 seconds validate the field and mark as invalid if error. I'm trying to use debouncing function but seems it's not working with TextField error property. Is it the good approach?

  const [email, setEmail] = useState('');

  export const emailHasError = (email) => {
    .... 
    return true; // if error
  }

  <TextField
    id="filled-basic"
    label="email"
    variant="filled"
    fullWidth
    error={email.length > 0 && debounce(emailHasError(email), 3000)}
    value={email}
    onChange={(e) => setEmail(e.target.value)}
  />
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In your method, debounce will not return the value which you are returning from the inner function. debounce will return a timer so it will always true

I have added one more state to store the invalid value. and using the same debounce function onkeyUp.

 const [email, setEmail] = useState('');
 const [invalidEmail, setInvalidEmail] = useState(false)
 export const emailHasError = (email) => {
    .... 
    setInvalidEmail(true) // if error
  } 

  const checkEmail = () => {
   setInvalidEmail(false);
   debounce(emailHasError(email), 3000)
  }

  <TextField
    id="filled-basic"
    label="email"
    variant="filled"
    fullWidth
    error={invalidEmail}
    value={email}
    onKeyUp={checkEmail}
    onChange={(e) => setEmail(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