DEV Community


React bind(this)

dmanias profile image dmanias ・1 min read

In React, whenever you define an event handler that uses "this", you need to add "this.methodName = this.methodName.bind(this)" to your constructor function.

This is not React-specific behavior; it is a part of how functions work in JavaScript. Generally, if you refer to a method without () after it, such as onClick={this.handleClick}, you should bind that method.

Discussion (1)

Editor guide
rachid3alaoui profile image