board数组包含4个数字,其中之一将被随机更改为数字1,我需要在单击时获取该数字的值。 每个板编号有4个按钮。
class GameContainer extends React.Component {
state = {
board: [0, 0, 0, 0]
};
generateBoard = () => {
const newBoard = this.state.board;
const random = Math.floor(Math.random() * 4);
newBoard[random] = 1;
return newBoard;
};
findWinner = () => {
};
componentWillMount = () => {
const board = this.generateBoard();
console.log("BOARD:", board);
this.props.createBoard(board);
console.log("Board created");
};
onClick = event => {
console.log("Click received!", event.target.id);
this.findWinner();
};