I have a for loop that needs to render div
s according to some logic:
let allRecords;
if (this.state.allRecords) {
allRecords = (() => {
let paramOne = this.state.paramOne;
let paramTwo = this.state.paramTwo;
let paramThree = this.state.paramThree;
let paramFour = this.state.paramFour;
let paramFive = this.state.paramFive;
let paramSix = this.state.paramSix;
for (let i = 0; i < this.state.length; i++) {
let res;
res = (
<div>
<div className="event-result-table-container">
<div className="result-cell">{paramOne[i]}</div>
<div className="result-cell">
<span>{paramTwo[i] ? "Win" : "Lose"}</span>
</div>
<div className="result-cell">{paramThree[i]}</div>
<div className="result-cell">{paramFour[i]}</div>
<div className="result-cell">{paramFive[i]}</div>
<div className="result-cell-last">{paramSix[i]}</div>
</div>
</div>
);
return res;
}
})();
}
The six param
arrays all have a similar structure. For example, I have copied the paramSix
state array from the Chrome console, and it looks like this:
[
[
479,
480,
481,
482,
483,
484,
485,
486,
487
]
]
Expected Result: I want to see a bunch of res
blocks rendered (equal to this.state.length
), each with its correct value taken from the state arrays.
Observed result: Only one row of blocks gets rendered, but all the values are there (checked with React DevTools), as if it renders only one block of div
s, but puts all the values in their cells, instead of putting them in separate blocks.
What am I doing wrong here?