I have made a table that have some values. I want to use same table code with different values and use it for multiple tables.
My current code is
renderTable() {
const { recordsSect } = this.state;
let a = [];
a.push(recordsSector)
return recordsSector != null ? (
<table className="table table-bordered">
<thead>
<tr>
<th>Period/Range</th>
<th>30%</th>
<th>20%</th>
<th>10%</th>
</tr>
</thead>
<tbody>
{a.map(item =>
<tr key={item.id}>
<td>Daily</td>
<td>{item.f_dyn30_all}</td>
<td>{item.f_dyn20_all}</td>
<td>{item.f_dyn10_all}</td>
</tr>)
}
{a.map(item =>
<tr key={item.id}>
<td>Weekly</td>
<td>{item.f_wkn30_all}</td>
<td>{item.f_wkn20_all}</td>
<td>{item.f_wkn10_all}</td>
</tr>)
}
{a.map(item =>
<tr key={item.id}>
<td>Monthly</td>
<td>{item.f_mtn30_all}</td>
<td>{item.f_mtn20_all}</td>
<td>{item.f_mtn10_all}</td>
</tr>)
}
{a.map(item =>
<tr key={item.id}>
<td>Quarterly</td>
<td>{item.f_qrn30_all}</td>
<td>{item.f_qrn20_all}</td>
<td>{item.f_qrn10_all}</td>
</tr>)
}
{a.map(item =>
<tr key={item.id}>
<td>Interim</td>
<td>{item.f_inn30_all}</td>
<td>{item.f_inn20_all}</td>
<td>{item.f_inn10_all}</td>
</tr>)
}
</tbody>
</table>
) : null
}
I would to create 6 tables with the above without rewriting all the code.
And in each table 2 substring in td will be changed. ie f & all in item.f_qrn10_all(eg).
item.(variable)_qrn10_(variable) variable - that use some dynamic value
I would like to know a better option to do this.
item = { (variable): { qrn10: { (variable): (value) } } }