Skip to content

Instantly share code, notes, and snippets.

@PabloRegen
Last active March 4, 2019 06:40
Show Gist options
  • Save PabloRegen/609fb46a35f51f5d5004cde8f90e3127 to your computer and use it in GitHub Desktop.
Save PabloRegen/609fb46a35f51f5d5004cde8f90e3127 to your computer and use it in GitHub Desktop.
Create grid with a table
const BoardGrid = ({ boardStatus, onToggleCellStatus }) => {
const handleClick = (r,c) => onToggleCellStatus(r,c);
const tr = [];
for (let r = 0; r < totalBoardRows; r++) {
const td = [];
for (let c = 0; c < totalBoardColumns; c++) {
td.push(
<td
key={`${r},${c}`}
className={boardStatus[r][c] ? 'alive' : 'dead'}
onClick={() => handleClick(r,c)}
/>
);
}
tr.push(<tr key={r}>{td}</tr>);
}
return <table><tbody>{tr}</tbody></table>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment