I want to have a dynamic rendering of JSX as below;
<ColumnLayout container spacing={1}>
<ColumnLayout item xs={9}>
<b>{text}</b>
</ColumnLayout>
{showSubTextAndIcon ?
<ColumnLayout item xs={2}>
<span>{subText}</span>
</ColumnLayout>
<ColumnLayout item xs={1}>
<Icon />
</ColumnLayout>
: null
}
</ColumnLayout>
Thus, I want that only if "showSubTextAndIcon" is true, then render the subtext and Icon. Now the above does not work and I get a syntax error saying;
Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>
This works if I add a wrapping ColumnLayout. However, that messes my layout when showSubTextAndIcon is true.
{showSubTextAndIcon ?
<ColumnLayout container spacing={1}>
<ColumnLayout item xs={2}>
<span>{subText}</span>
</ColumnLayout>
<ColumnLayout item xs={1}>
<Icon />
</ColumnLayout>
</ColumnLayout>
: null
}
Note: ColumnLayout is derived from material ui library.