DEV Community

Discussion on: React Beginner Question Thread ⚛

Collapse
 
dan_abramov profile image
Dan Abramov • Edited

I see why you might find this cumbersome although to be honest I got used to it pretty quick and it stopped being a problem for me a few months into React.

In fact I found the ability to use any JS constructs liberating because as soon as the condition got more complicated I could extract it in a variable, a function call, a switch statement, an object property lookup, or any other valid JS code.

That said we do have some ideas about allowing something like

return (
  <div>
    *{
      if (obj.attr) {
        yield <Stuff />;
      }
    }
  </div>
)

to work (see this proposal).

Collapse
 
edmilsonrobson profile image
Edmilson Rocha

Interesting... Yeah, I can totally see how abstracting complex conditions into a variable can be useful. I guess it makes a lot of sense - it's all just javascript in the end.

Thanks for the answer!