I am trying to map an array of typescript interface objects and print its values in a table. My array looks something like this:
export interface data {
fields?: field[];
}
export interface field {
name: string;
description: string;
subfields: subfield[];
}
But I want to print only that field
which has field.name
equal to requiredName
On usage of ternary operator to define condition I am getting the following error:
Expected an assignment or function call and instead saw an expression
I would appreciate some help in defining conditional statements to map my object. I have used ternary operator before too but only for printing value in a table cell instead of dynamically creating one.
Here´s my code so far:
<Table>
<TableBody>
<TableRow >
<TableCell>
{props.fields.map((it) =>
{it.name===requiredName ? (
<Table>...</Table>
) : (
null
)}
)}
</TableCell>
</TableRow>
</TableBody>
</Table>
Thanks in advance.
export interface data { fields?: field[]; }
isn't the ternary syntax wrong here ? ? - jarivak