I have the render method in a react component shown below, which displays a 4 by 4 grid.
I want to split the products into groups of 4, how can I do this?
For example if I have 12 products, 3 groups of 4, I need to display
XXXX
XXXX
XXXX
I could have productList1, productList2, productList3, but I need it to be extensible, for instance the grid may take 40 products, so would be a 10 x 4 grid.
render() {
let productList = this.props.products.map( (p, i) => {
if(i < 4){
return (
<ul key={i}><li>{p.name}</li></ul>
);
} else {
return (
<span>not sure</span>
);
}
});
return (
<section>
{/* 4 products */}
<div className="row">
{productList}
</div>
{/* the next 4 */}
<div className="row">
{productList2}
</div>
{/* and the next 4 */}
<div className="row">
{productList3}
</div>
</section>
)
}
mapto do that.