I need to map through two different arrays adding them as rows to a single table. To do this I am attempting to use a counter instead of index (since react requires a unique key per iteration). I can't use index for the key because I have to concatenate and that makes the indexes not unique per row. So instead, I am attempting with a counter but am getting stuck on how I should increment the number...
...
{dateTable.categories.map((category, indexThree, categories) =>
{
let rowCounter = 0;
const firstRows = category.firstRows.map((row, indexFour, firstRowsArr) =>
<tr key={indexFour}>
{indexFour === 0 ?
<td>
<h5>{category.name}</h5>
</td> : <td />
}
<td>{row.valOne}</td>
<td style={{backgroundColor: "#ffedbc"}}>{row.valTwo}</td>
<td>{row.valThree}</td>
<td>{row.valFour}</td>
</tr>
);
const secondRows = category.secondRows.map((row, indexFive, secondRowsArr) =>
<tr key={indexFive+rowCounter}>
{indexFive === 0 && category.firstRows.length === 0 ?
<td>
<h5>{category.name}</h5>
</td> : <td />
}
<td>{row.valOne}</td>
<td>{row.valTwo}</td>
<td>{row.valThree}</td>
<td>{row.valFour}</td>
</tr>
);
console.log("rowCounter", rowCounter);
return firstRows.concat(secondRows);
}
)}
...