Usually if you have something like:
<SomeComponent foo={bar} />
you can make this optional using triple:
{bar ? <SomeComponent foo={bar} /> : null}
But what if the block you start with contains a component plus some text (one space) and a variable, for example:
<SomeComponent foo={bar} /> {foobar}
A wrapper in parentheses will not work:
{bar ? (<SomeComponent foo={bar} /> {foobar}) : null}
and in fact, the only way to make it work is to wrap everything in another element:
{bar ? <span><SomeComponent foo={bar} /> {foobar}</span> : null}
Is there any other way to tell React that:
<SomeComponent foo={bar} /> {foobar}
is a discrete piece, so I can use it in ternary (inside JS, not JSX, logic) ... without adding meaningless shell elements?
source
share