re: React Beginner Question Thread ⚛ VIEW POST

TOP OF THREAD FULL DISCUSSION
re: As someone that comes from a Vue background, conditionally rendering things in React look a bit cumbersome to me. In Vue, I just use a v-if directi...
 

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).

 

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!

code of conduct - report abuse