In a React component I need to render a Select conditionally in the following way:
- If a certain prop exists, Select is wrapped in a parent tag structure of
<div><Form>..</Form></div>
- Otherwise the Select is not wrapped in these parent tags.
Obviously I can do ? :
duplication which redefines the Select as
<code>{props.flag
?
<div className="formField">
<Form error={props.error}>
<Select...>
{/* Huge Select with lots of definitions */}
</Form>
</div>
:
<Select...>
{/* Huge Select with lots of definitions */}
</code>
<code>{props.flag
?
<div className="formField">
<Form error={props.error}>
<Select...>
{/* Huge Select with lots of definitions */}
</Form>
</div>
:
<Select...>
{/* Huge Select with lots of definitions */}
</code>
{props.flag
?
<div className="formField">
<Form error={props.error}>
<Select...>
{/* Huge Select with lots of definitions */}
</Form>
</div>
:
<Select...>
{/* Huge Select with lots of definitions */}
But I don’t want to duplicate that huge Select snippet. Is there a way to isolate a snippet and quickly plug it in as appropriate?