ES6 - Syntax

0 votes
89 views
added Mar 8, 2019 in ES6 by LC Marshal Captain (25,770 points)

Extra careful with the meaning of this in JSX callbacks. In JavaScript, class methods aren't bound by default. It'll throw undefined  if you forget to bind this.handleClick.

// This binding (.bind) is a must to make `this` work in the callback
this.handleClick = this.handleClick.bind(this);
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...