Hacker News new | ask | show | jobs
by jpochtar 1034 days ago
Yeah you have to do

  <If cond={...} then={() => 
    ...
  } els={() => 
    ...
  } />
so the `then` and `els` branches only get evaluated if needed
3 comments

We use ternary extensively with in JSX. Keeps the logic in vanilla JS

{ some_condition ? (

  <H2>It was true</H2>
) : (

  <H2>It was false</H2>

)
Even though I'm a JS programmer myself and I do use similar constructs once in a while, I have to admit that this gets dangerously close to the Greenspun's tenth rule... In times like this I miss proper Lisp macros.
Which has ugly untax IMO