Re:Learning Node.js and React while building a product
by miroslavpopovic on Tuesday June 13, 2017 @12:31PM
(#14546045)
Yep, we are using arrow functions and other ES2015+ goodies, but they don't help with event handlers. In fact, I believe class property syntax helps with that, but we only figured it out after we built these few pages and components necessary for the web app part.
Re:Learning Node.js and React while building a product
by coldtea on Tuesday June 13, 2017 @04:03PM
(#14548113)
>Yep, we are using arrow functions and other ES2015+ goodies, but they don't help with event handlers.
They do. Just do:
myHandler = (v) => {
...
}
and you don't need to bind in the constructor anymore. You'll need to use Babel of course to transpile that.
Re:Learning Node.js and React while building a product
by miroslavpopovic on Tuesday June 13, 2017 @06:07PM
(#14549072)
Yes, class properties syntax. I mentioned that in the article.
Re:Learning Node.js and React while building a product
by coldtea on Tuesday June 13, 2017 @07:28PM
(#14549555)
Hmm, so why do you say "but they don't help with event handlers"? Because it's not yet standard?
Re:Learning Node.js and React while building a product
by miroslavpopovic on Wednesday June 14, 2017 @11:35AM
(#14553476)
Sorry, I didn't think about the arrow functions being used in class property syntax too. :) So yes, they do help with event handlers, I stand corrected.
Re:Learning Node.js and React while building a product
by nbclark on Tuesday June 13, 2017 @12:32PM
(#14546052)
One note: From what I've read, using arrow functions as props in a render method of a component will create new functions each render, so you might end up with a good bit more GC than normal. There are some nice little mix-ins that will autobind to remove the need to remember to .bind everything.
Re:Learning Node.js and React while building a product
by Androider on Tuesday June 13, 2017 @01:29PM
(#14546635)
Nowadays you can just stick a class property anywhere in your React component:
handleSomething = (params) => {
...
};
and the use it in your render function like this without any binding: <Foo onSomething={this.handleSomething}/>
Re:Learning Node.js and React while building a product
by miroslavpopovic on Tuesday June 13, 2017 @04:04PM
(#14548116)
Yes, class properties are the way to go.
Re:Learning Node.js and React while building a product
by nbclark on Tuesday June 13, 2017 @01:42PM
(#14546792)
Good suggestion - Thank you
Re:Learning Node.js and React while building a product
by miroslavpopovic on Tuesday June 13, 2017 @12:41PM
(#14546139)
Not using arrow functions in JSX code to define error handler. Yes, I believe you are right, that would create multiple handlers.
The only annoyance is dealing with binding event handlers to items/components in a list. Generally you need to abstract the list item into it's own component and do the event handler binding there.
I don't use .bind() anywhere in my react code.