I'm kind of following this YouTube tutorial to make my own Tetris game in react. I'm doing this to train my react skills. I'm trying to come up with my own solutions and sometimes check what Thomas did in the tutorial.
I'm having a problem now when I try to populate the map grid with is a 2d array to change the color of one single cell, it change the whole row of cells.
const STAGE_WIDTH = 12;
const STAGE_HEIGHT = 20;
const stageCells = Array.from(Array(STAGE_HEIGHT), () =>
new Array(STAGE_WIDTH).fill([0, 1])
)
stageCells[0][0].color = "blue";
console.log(stageCells);
return (
<StageGrid>
{stageCells.map(cells => cells.map((cell, key) =>
<Cell key={key} color={cell.color} />
))}
</StageGrid>
)
The console.log
shows that its changing all the items in the 0 position, I only what to change one.
Console output: