DEV Community

loading...

React bind(this)

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)

Collapse
rachid3alaoui profile image
Rachid Amrani Alaoui

Thank you.