classButtonextendsReact.Component{handleClick=(e)=>{// no binding}render(){return<buttononClick={this.handleClick}>hi</button>;
}}
Note they're not standardized yet. But they're so widely used that if the syntax changes or proposal gets dropped, there's definitely going to be an automated migration path (i.e. a codemod).
Although it looks quite cool I'm really not at ease with class properties because of how they could be confusing, scope wise.
A fat-arrow function is supposed to be bound to the lexical scope in which it is defined and that is very much not the case here, which could lead to some confusions.
Yo! I'm Adam. I'm a web developer based in London, UK and I'm open for messages and questions about work or code or anything really.
P.s I'm the one with the beard in my profile pic ✌🏻🐵
Can't believe how old this comment is now! I still check it all the time for syntax lol - It's literally become it's own google search for me! Thanks for the (probably)10+ times this has helped!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I tend to use class properties:
Note they're not standardized yet. But they're so widely used that if the syntax changes or proposal gets dropped, there's definitely going to be an automated migration path (i.e. a codemod).
Although it looks quite cool I'm really not at ease with class properties because of how they could be confusing, scope wise.
A fat-arrow function is supposed to be bound to the lexical scope in which it is defined and that is very much not the case here, which could lead to some confusions.
I don't know exactly where to stand :D
We’ve been using them in production at Facebook for about a year now, and haven’t seen much confusion in practice.
As a React newbie this is a game-changer for me. No more headaches with debugging just because I forgot to bind this to functions in the constructor!
Can't believe how old this comment is now! I still check it all the time for syntax lol - It's literally become it's own google search for me! Thanks for the (probably)10+ times this has helped!