I have a simple component called GridSquare:
import React from 'react';
import './GridSquare.css'
const GridSquare = (props) => {
return (
<div className="empty-square">
</div>
)
}
export default GridSquare;
The css file of GridSquare is just making the div a simple gray square:
.empty-square{
display: inline-block;
height: 30px;
width: 30px;
background-color: #555;
}
I'm trying to create a grid of these squares with a component called Grid. I'm having difficulties with mapping the 2d array. Mapping one dimensional array works fine but the 2d array just prints out empty divs.
import React from 'react';
import GridSquare from './GridSqure'
const GameGrid= () => {
const gamegrid=new Array(20);
for(let i =0; i<gamegrid.length; i++)
gamegrid[i] = new Array(20);
console.log(gamegrid);
return(
<div>
{
gamegrid.map((row)=>
{
return (
<div>
{
row.map(() => <GridSquare/>)
}
</div>
)})
}
</div>
)
}
export default GameGrid;
What am I missing?