From 09b5009dfd55828c0d8b331aea0516d0f6edc5ea Mon Sep 17 00:00:00 2001 From: djmil Date: Mon, 31 Jul 2023 17:45:13 +0200 Subject: [PATCH] taking turns --- src/App.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 5cb99b1..494c5f2 100644 --- a/src/App.js +++ b/src/App.js @@ -14,13 +14,18 @@ function Square({value, onSquareClick}) { } function App() { - + const [xIsNext, setXIsNext] = useState(true); const [squares, setSquares] = useState(Array(9).fill(null)); function handleClick(i) { const nextSquares = squares.slice(); - nextSquares[i] = "X"; + if (xIsNext) { + nextSquares[i] = "X"; + } else { + nextSquares[i] = "O"; + } setSquares(nextSquares); + setXIsNext(!xIsNext); } return (