Re:TypeScript support for ES Next pipeline operator
by mercer on Friday September 21, 2018 @05:08PM
(#18042659)
The latter version seems to be the one I most commonly see, except _handleClick() is just handleClick() repeated. Am I correct in assuming this is considered idiomatic at this point?
Re:TypeScript support for ES Next pipeline operator
by antonkm on Friday September 21, 2018 @05:34PM
(#18042825)
Yes, I'd say so.
Re:TypeScript support for ES Next pipeline operator
by mercer on Friday September 21, 2018 @06:31PM
(#18043158)
Is this better somehow? I feel like I should know this, but it's Friday night and I'm tired, but isn't the constructor fired on every instance of the component? And if so, is this a better approach for any particular reason other than clarity?
Re:TypeScript support for ES Next pipeline operator
by aenigmaclamo on Friday September 21, 2018 @06:39PM
(#18043205)
It is fired on every instance of the component. However, if you create the arrow function in the render function, it'll be created for every render. Since React keeps the component instances around between renders, it can be a lot better.
Re:TypeScript support for ES Next pipeline operator
by mercer on Friday September 21, 2018 @06:45PM
(#18043235)
Ah, that makes sense. Do you by any chance know of any articles that go further into how this works?
Re:TypeScript support for ES Next pipeline operator
by RunawayGalaxy on Friday September 21, 2018 @11:18PM
(#18044267)
To avoid it, you can do (sorry for bad formatting):
You can also bind handleClick inside the constructor without the arrow.