I am new to react and I am using a carbon react library I am just wondering how can I put an if statement in map function.
It just writes the if statement in like it is normal string.
<StructuredListBody>
{matchingResults?.map((X, i) =>
<StructuredListRow}>
{if (X?.status.includes(Working)){
<StructuredListCell>{X?.status}</StructuredListCell>}
else
{<StructuredListCell>{X?.checking}</StructuredListCell>}};
</StructuredListRow>
)}
</StructuredListBody>
--- additional information I simplified the code but I am looking at cant use a ternary operator because there will be more than 2 conditions.
It is more like this I still don't get how to return a specific component in a component. I am trying to change the color. The only thing that came to mind is to use the same again
<StructuredListBody>
{matchingResults?.map((X, i) =>
<StructuredListRow key={`row-${row.id} -${i}`}>
if (X?.status.includes(Working) {
<StructuredListCell key={`cell-${row.id}} noWrap style={{paddingBottom: '.5rem', color: 'red'}}>
{X?.status}
</StructuredListCell>}
else
{<StructuredListCell key={`cell-${row.id} noWrap style={{paddingBottom: '.5rem', color: 'yellow'}}>
{X?.status}
</StructuredListCell>}
)}
</StructuredListBody>