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

441
Views
Bind vs Arrow Function when passing onChange props (React)

When we pass an arrow function to an event handler i.e. onClick={() => myFunction()}, we are causing un-necessary re-renders since this is a function definition.

Instead, should onClick={myFunction.bind(this)} be used instead of the arrow function whenever we call a function on an event handler and want access to this? Since it is only using a reference to the function, we are not causing a re-render each time.

Is the above understanding correct? If so, why would we ever use an arrow function as an event handler prop? It seems that ever since the introduction of ES6, using .bind like we do here is not usually recommended, but since it would not cause unnecessary re-renders shouldn't this be the best practice?

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

0

Since it is only using a reference to the function, we are not causing a re-render each time

You're wrong.

The bind method returns a new function (so will trigger a re-render).


To avoid re-renders, make use of the useCallback hook.

Or, since you don't appear to be making use of this inside myFunction (otherwise () => myFunction() would break it), just pass myFunction itself without creating a new function.

onClick={myFunction}
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!