I heard in an Udemy ReactJS class, using an arrow function for an onClick handler will cause performance issue and unnecessary render for the component:
return (
<button onClick={() => this.doSomething()}>
or what about
return (
<Foo onClick={() => this.doSomething()}>
Is it true? I don't quite see how it can cause unnecessary re-render, as the whole subtree from this component and down should need to be re-rendered anyway.
The recommendation is to use one of the following:
1) use
return (
<button onClick={this.doSomething.bind(this)}>
2) in the constructor
this.doSomething = this.doSomething.bind(this);
3) in the class definition, use arrow function instead:
const doSomething = () => { };