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

238
Visualizações
requestAnimationFrame inside if statement leads to timestamp undefined - outside of 'if' it works

I am using the following form in React

<form onSubmit={e => {HandleSubmit(e)}}>
<div ref={textArea} className="enclosing-divs">
<label className="form-label" htmlFor="message">Message:</label>
<textarea className="input-field" style={{ height: "160px", paddingTop: "2px", resize: "none" }} id="message" required />
</div>
<button className="submit-button" type="submit"></button>
</form>

On submitting the form, I want the textarea (which I have assigned to a ref) to disappear after 4 seconds have passed with this function I am calling above:

function sendEmailAnimation(now) {
if (now >= 4000) {
textArea.current.style.display = "none"}
if (now <= 10000) {
requestAnimationFrame(sendEmailAnimation)}
}

function HandleSubmit(event) {
event.preventDefault()
sendEmailAnimation()}

PROBLEM: the code above does not work, BUT if I remove the if-statement for requestAnimationFrame(sendEmailAnimation) so that it always runs THEN it works, but then I would have a never ending loop. With the if statement I only know that somehow the timestamp does not work like it should and remains "undefined", I just have no idea why - Thanks for any support!

about 4 years ago · Juan Pablo Isaza
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