I am trying to set up a conditional statement that basically takes a button and says when I click on the button I want an X to appear and I want the button's color to change to red currently the whole board is changing to the color I'm asking it to.
I've tried putting the condition in different places to see if that would work it doesn't work where does the conditional statement need to be
if (this.state.xIsNext = 'X') {
backgroundColor='red';
}
else if (this.state.xIsNext = 'O') {
backgroundColor='yellow';
}
}
renderSquare(i, backgroundColor) {
return (
<Square
value={this.state.squares[i] || 'X'}
onClick={() => this.handleClick(i)}
/>
);
}
render() {
const status = 'Next player: X';
return (
<div>
<div className="status">{status}</div>
<div className="board-row">
{this.renderSquare(0)}
{this.renderSquare(1)}
{this.renderSquare(2)}
</div>
<div className="board-row">
{this.renderSquare(3)}
{this.renderSquare(4)}
{this.renderSquare(5)}
</div>
<div className="board-row">
{this.renderSquare(6)}
{this.renderSquare(7)}
{this.renderSquare(8)}
</div>
</div>
);
}
}
the project can also be viewed herehttps://codepen.io/zachary-blumstein/pen/KKPJaLG?editors=0010