D'oh! Working with React and wondered why my UI was partial:
render () {
return (
<A prop={value} />,
<B prop={value} />
)
}
Reminded me how cool the comma operator is in JavaScript:
return Expr, …, Expr
Evaluates each expression, but returns result of last.
Ti be more clear, the return statement returns the result of the Expression (if any) to its right. Expressions can contain Expressions. So each of the expressions in a list are evaluated, but only the result of the final is returned.
I think I first read about this little detail in one of @rauschma's fantastic deep-dive posts, but I'm not sure which one.
I just tipped 2ality.com using the Brave Browser. Learn more at brave.com/tips. #TipWithBrave
It might have been this 2012 post (section 2.2, specifically) where I first read of this behavior: 2ality.com/2012/09/expres….
Years ago Axel's blog convinced me that you could take any small detail of JavaScript, and blow it up into a large and exciting discussion.
Now, back to my React app where I need to remove the comma and wrap my components in a common ancestor 😂
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.
