Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!