I am working with some data collected from a Json file. With a react fetch function I have created an object called "category_evolution". I am trying to use a map function to create a table with that object.
category_evolution =
[
{
"name": "01/02/2023",
"data": [
{
"id": 30,
"category": "Criptomoedas",
"category_total_brl": "12000.00",
"category_total_usd": "2400.00",
"date": "01/02/2023"
},
{
"id": 28,
"category": "REITs",
"category_total_brl": "16000.00",
"category_total_usd": "3200.00",
"date": "01/02/2023"
},
{
"id": 26,
"category": "Stocks",
"category_total_brl": "20100.00",
"category_total_usd": "4020.00",
"date": "01/02/2023"
}
]
},
{
"name": "01/01/2023",
"data": [
{
"id": 29,
"category": "Criptomoedas",
"category_total_brl": "10000.00",
"category_total_usd": "2000.00",
"date": "01/01/2023"
},
{
"id": 27,
"category": "REITs",
"category_total_brl": "15000.00",
"category_total_usd": "3000.00",
"date": "01/01/2023"
},
{
"id": 25,
"category": "Stocks",
"category_total_brl": "20000.00",
"category_total_usd": "4000.00",
"date": "01/01/2023"
}
]
}
]
Here is my table code:
<table className="table">
<thead>
<tr>
<th scope="col">Categoria</th>
{category_evolution.map(({ name }) => (
<th scope="col" key={name}>{name}</th>
))}
</tr>
</thead>
<tbody>
{category_evolution.map(({ data }) =>
data.map(({ id, category, category_total_brl }) => (
<tr key={id}>
<td>{category}</td>
<td>{category_total_brl}</td>
</tr>
))
)}
</tbody>
</table>
The output of this code is a table like that
Categoria 01/02/2023 01/01/2023
Criptomoedas 12000.00
REITs 16000.00
Stocks 20100.00
Criptomoedas 10000.00
REITs 15000.00
Stocks 20000.00
But I would like to achieve an output like this:
Categoria 01/02/2023 01/01/2023
Criptomoedas 12000.00 10000.00
REITs 16000.00 15000.00
Stocks 20100.00 20000.00
I appreciate any help you can provide.