News for hackers. Stuff that matters.
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.