ES6 - Syntax

0 votes
177 views
added Mar 8, 2019 in ES6 by LC Marshal Captain (25,790 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.
...