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

279
Views
setTimeout() doesn't register event target value

I have the following code:

const handleInputChange = (evt) => {
    evt.preventDefault();
    setTimeout(() => {console.log(evt)}, 500);
}

I have a search bar and every time I type something into the handleInputChange function gets called. When looking at the console I find that the evt.target.value field is always set to an empty string regardless of any inputs I have made.

However, if I modify the code to be

const handleInputChange = (evt) => {
    evt.preventDefault();
    const term = evt.target.value;
    setTimeout(() => {console.log(term)}, 500);
}

My target value always gets printed correctly. Can anyone help clarify on why this happens?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When you pass the full event object you and you print the value you are getting the current object status because it is a reference to the original object, so if you clear de input or the event is destroyed your data is not available.

When you save the current event target value you do not care about event status so it is better to save your value instead propagate the event reference through functions.

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