Answer the question
In order to leave comments, you need to log in
How to make a grid with 4 elements per row in react+bootstrap?
There is a product catalog. The array of goods is obtained from the store. It is necessary to display all this in a grid of 4 elements per line and that everything be in the center and that each card be the same width. Tell me how to do this with a simple array of goods? It is not clear how to sort through the array to make rows (className="row")
Now I did this:
<div className="container">
<div className="row">
{
this.props.catalog.map(product => (
<Card
className="col"
key={product.uid}
name={product.name}
price={product.price}
imageUrl={product.imageUrl}
weight={product.weight}
diameter={product.diameter}
/>
))
}
</div>
</div>
Answer the question
In order to leave comments, you need to log in
It is necessary to display all this in a grid of 4 elements per line <...> It is not clear how to sort through the array to make lines
const { items } = this.state;
const rows = [...Array(Math.ceil(items / 4))].map((n, i) => items.slice(i * 4, (i + 1) * 4));
{rows.map(n => (
<div className="row">
{n.map(m => <div>{m}</div>)}
</div>
))}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question