News for hackers. Stuff that matters.
Re:What should go into JSX 2.0? by msoad on Sunday October 16, 2016 @12:17PM (#12719310)
It's the extreme fanboyism there! Wrapping every component that has `if` attribute with an `if` statement should not result into that:

    <div *if={cond1 && cond2}>
        <div>foo</div>
    </div>

    // results to
    if (cond1 && cond2) {
        return React.createElement('div', null, 
            React.createElement('div', null, 'foo')
        );
    }
I'm not sure why this is bad? Because it's looking like Angular?!!
Re:What should go into JSX 2.0? by coderzach on Sunday October 16, 2016 @12:47PM (#12719499)
It's bad because it's inconsistent with how every other attribute in jsx works. Nothing else in jsx changes the control flow of the code.
Re:What should go into JSX 2.0? by msoad on Sunday October 16, 2016 @12:49PM (#12719514)
It is 2.0 so it can have breaking changes
Re:What should go into JSX 2.0? by exogen on Sunday October 16, 2016 @02:59PM (#12720309)
The parent didn't mention anything about backwards compatibility. They're saying 2.0 with such a change would be inconsistent with itself. And they're right.
Re:What should go into JSX 2.0? by cel1ne on Sunday October 16, 2016 @12:23PM (#12719348)
I think ternary expression are rather ok here, though not perfect:

    {cond1 && cond2
     ? <div>foo</div>
     : null
    }
Re:What should go into JSX 2.0? by danneu on Sunday October 16, 2016 @12:54PM (#12719543)
And you can inline if-statements with an IIFE when you need a little more space:

    {(() => {
      if (cond1 && cond2)
        return <div>foo</div>
      else 
        ...
    })()}
Though it makes GitHub think it's a Clojure file.
Re:What should go into JSX 2.0? by vanderZwan on Sunday October 16, 2016 @12:58PM (#12719570)

     {(() => {
     })()}
Honestly I can't decide if I think this is ugly or beautiful. It's like the buffalo buffalo of JS.
Re:What should go into JSX 2.0? by olalonde on Sunday October 16, 2016 @05:32PM (#12721105)
That's something the "do expressions" ECMAScript proposal is meant to solve:

    {do {
      if (cond1 && cond2)
        <div>foo</div>
      else 
        ...
    }}
If JSX decides to implement "implicit" "do expressions", I suppose it would just look like this:

    {
      if (cond1 && cond2)
        <div>foo</div>
      else 
        ...
    }
http://wiki.ecmascript.org/doku.php?id=strawman:do_expressio...
Re:What should go into JSX 2.0? by spirit23 on Sunday October 16, 2016 @01:25PM (#12719702)
It’s interesting to see that there are so many ways of doing conditions in JSX. I myself wrote a tiny library (http://github.com/yuanchuan/cond) for it several months ago and thought it made the code looks clean but suffers the same undefined issue though.
Re:What should go into JSX 2.0? by _betty_ on Sunday October 16, 2016 @02:51PM (#12720259)
I'd love for them to adopt something similar to Razor (Microsoft server side html engine)

note: i've changed your example to show code inside html tags, i'm aware it does something different to yours.

conditionals

  <div>
    @if(cond1 && cond2) {
      <div>foo</div>
    }
  </div>

loops

  <div>
    @for(var i in collection) {
      <div></div>
    }
  </div>

variables

  <div>
    @variable
  </div>

ternary/longer statement

  <div>
    @(variable ? 1 : 2)
  </div>
Re:What should go into JSX 2.0? by tmzt on Sunday October 16, 2016 @07:30PM (#12721684)
The one negative thing I've found with Razor is the ambiguous start and end of statements or expressions vs html. Sometimes a @ is required before a statement and sometimes its a syntax error, conversely statements and and expressions may be rendered as text if they follow html with a @. I think jsx's approach is clearer.
Re:What should go into JSX 2.0? by _betty_ on Monday October 17, 2016 @09:23PM (#12731283)
admittedly there is the occasional moment I hit where I need an extra @ or @: so it's not perfect, but I have much less issue reading that format than the { true && <element /> } syntax, also think @if is a lot nicer than <if>.

Maybe just a personal thing.

Re:What should go into JSX 2.0? by Yaggo on Sunday October 16, 2016 @01:02PM (#12719588)
<div if={expression} />

translates to

React.createElement('div', {if: <expression>})

This is bad because createElement always gets execute, whether the if expression evaluated to true or false. Changing this semantic would be messy.