taking turns
This commit is contained in:
parent
382a659279
commit
09b5009dfd
@ -14,13 +14,18 @@ function Square({value, onSquareClick}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
const [xIsNext, setXIsNext] = useState(true);
|
||||||
const [squares, setSquares] = useState(Array(9).fill(null));
|
const [squares, setSquares] = useState(Array(9).fill(null));
|
||||||
|
|
||||||
function handleClick(i) {
|
function handleClick(i) {
|
||||||
const nextSquares = squares.slice();
|
const nextSquares = squares.slice();
|
||||||
|
if (xIsNext) {
|
||||||
nextSquares[i] = "X";
|
nextSquares[i] = "X";
|
||||||
|
} else {
|
||||||
|
nextSquares[i] = "O";
|
||||||
|
}
|
||||||
setSquares(nextSquares);
|
setSquares(nextSquares);
|
||||||
|
setXIsNext(!xIsNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user