I have an array object that looks like this: 
This is coming from parent component.
I want to display these in a table with all the headings(key) in a single column and their values in other columns. It should look something like this:
I am doing like this:
In my child component I am calling function like this for object coming from parent:
renderYear() {
if (this.props.total_calculation.length === 0) {
return null
} else {
const Year = this.props.total_calculation.map(
({ Year }) => Year
)
return Year.map(function (d, key) {
return (
<td key={key} colSpan="2">
{(d)}
</td>
)
})
}
}
This is creating td for all the values of each key in the objects(in this function it is year).
And in its render I made a table and render all these tds like this:
<table>
<tbody>
<tr className='year'>
<td>Year</td>
this.renderYear()
</tr>
I know this is not a good coding way because for each key(like year, rent_increase,...) I have to make a separate function and then render it.
Can you please suggest some efficient way to do this? or if I can optimize the map function.