DEV Community

dmanias
dmanias

Posted on

1

React bind(this)

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.

Top comments (1)

Collapse
 
rachid3alaoui profile image
Rachid Amrani Alaoui

Thank you.

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series