Why would you need to bind event handlers to “this”?

Technology CommunityCategory: ReactWhy would you need to bind event handlers to “this”?
VietMX Staff asked 3 years ago

You need to do this in order for this to refer to the object instance of the React component class in your callback code, otherwise this will be undefined. An alternative is to use arrow functions in your event handlers and ‘this’ will be initialized as expected.