Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Thanks for expanding! And do you see my other three refactorings similarly lacking?

No, all four are fine and most people use them in code all the time. They're not completely identical to ternary operators because they move the location of the JSX outside the place where it's used, which can make it harder to read the code at a glance.

> it sounds as if you just didn't like JavaScript

Yeah, I see that as a failure of EcmaScript, as I said in the first comment. JSX has to work within the unfortunate boundaries of the language.

> for the small gain of not needing the curly braces and a return statement, you pay a huge cost of not being able to use any statements in your code

That wasn't intended to be a meaningful part of the example, I was just writing the shortest component that let me show a particularly style which would be nice to have in EcmaScript instead of ternary operators.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: