Last active
March 4, 2019 06:40
-
-
Save PabloRegen/609fb46a35f51f5d5004cde8f90e3127 to your computer and use it in GitHub Desktop.
Create grid with a table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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