Why do I have to .bind(this) for methods defined in React component class, but not in regular ES6 class

The value of this primarily depends on how the function is called. Given d.speak();, this will refer to d because the function is called as an “object method”.

But in <div>{this.renderElements}</div> you are not calling the function. You are passing the function to React which will call it somehow. When it is called, React doesn’t know which object the function “belonged” to so it cannot set the right value for this. Binding solves that

I actually think what you really want is

<div>{this.renderElements()}</div>
//         call function ^^

i.e call the function as an object method. Then you don’t have to bind it.


Have a look at MDN to learn more about this.

Leave a Comment