In React I have a ternary operator returning a component if a condition is met:
{ this.state.houseHoldGroup.length > 0 ? (
<Table className="align-items-center table-flush" responsive>
<thead className="thead-light">
<tr>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{this.checkHouseholdGroup()}
</tbody>
</Table>
) : null }
Works good.
Inside this component I have a method: this.checkHouseholdGroup()
The expected behavior is for this method to return the table data inside <tbody></tbody>
checkHouseholdGroup = () => {
const householdDetails = this.state.houseHoldGroup;
householdDetails.forEach(el => {
console.log(el.firstHousehold)
return (
<tr>
<th scope="row">{el.firstHousehold}</th>
<td>{el.lastHousehold}</td>
<td>
<Button
color="primary"
href="#pablo"
onClick={e => e.preventDefault()}
size="sm"
onClick={e => this.submitMember(e)}>
Update
</Button>
</td>
<td>
<Button
color="primary"
href="#pablo"
onClick={e => e.preventDefault()}
size="sm"
onClick={e => this.submitMember(e)}>
Delete
</Button>
</td>
</tr>
)
})
}
I can confirm the element has data. I console.log(el.firstHousehold) can see it's not empty. What am I doing wrong? The expected result would be that it would return my with the data in it.