From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

This keyword confusion

This keyword confusion

Hello and welcome back. Let's resume from this keyboard confusion. In class components, this is used to refer the component instance. For example, consider this class component. We have a welcome class component, which has a constructor, which is having the props and Inside it, we are using this to refer the instance of this specific class. For example, this.state is equal to the name and then we have the handleClick function and we want to show the name state in the console. Over here that this is going to be required. Now let's discuss why this is actually confusing. Now let's discuss why this is actually confusing. We often have to bind methods manually in the constructor or use the arrow functions Or at times, we can forget to bind the results in the link, the class component and it can result into undefined. In JavaScript, you know that we have to handle this keyword very carefully because in order to not being able to bind our variables or we are manually doing something in the…

Contents