I wanted to render an array into a 2d grid (3 rows and 3 columns). The array itself is just a one-dimensional array.
const array = Array.from({ length: 9 }, (_, i) => i + 1);
I have a React component that renders it into a list of div
export default function App() {
return (
<div className="App">
<div className="grid">
{array.map((cell) => (
<div className="cell">{cell}</div>
))}
</div>
</div>
);
}
Now the cells are just stack on each other which is expected. I wonder if there is a way to make it a 3 x 3 grid without having to change the existing DOM structure by only adding styles?