Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on New React website. Parent comment
onClick = {this.handleClick}
This is due to the way "this" is scoped in JS.
Dan mentions that it works fine if you instead do: onClick = {() => this.handleClick()}
This is using the new ES6 arrow functions which fix the "this" scoping problem.
Another alternative is to use bind() inside the onClick and set "this" to the correct value that you want.
onClick = {this.handleClick.bind(this)}
There are no comments on this comment yet.
onClick = {this.handleClick}
This is due to the way "this" is scoped in JS.
Dan mentions that it works fine if you instead do: onClick = {() => this.handleClick()}
This is using the new ES6 arrow functions which fix the "this" scoping problem.
Another alternative is to use bind() inside the onClick and set "this" to the correct value that you want.
onClick = {this.handleClick.bind(this)}