Last active
March 5, 2019 00:02
-
-
Save PabloRegen/f74f1bcb3431408aac67d496a6c72a58 to your computer and use it in GitHub Desktop.
Toggle an individual cell status
This file contains hidden or 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
class App extends Component { | |
state = {...}; | |
runStopButton = () => {...} | |
handleClearBoard = () => {...} | |
handleNewBoard = () => {...} | |
handleToggleCellStatus = (r,c) => { | |
const toggleBoardStatus = prevState => { | |
const clonedBoardStatus = JSON.parse(JSON.stringify(prevState.boardStatus)); | |
clonedBoardStatus[r][c] = !clonedBoardStatus[r][c]; | |
return clonedBoardStatus; | |
}; | |
this.setState(prevState => ({ | |
boardStatus: toggleBoardStatus(prevState) | |
})); | |
} | |
// Other methods ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment