diff --git a/src/App.js b/src/App.js index 7115bfb..0841d47 100644 --- a/src/App.js +++ b/src/App.js @@ -13,10 +13,7 @@ function Square({value, onSquareClick}) { ); } -function Board() { - const [xIsNext, setXIsNext] = useState(true); - const [squares, setSquares] = useState(Array(9).fill(null)); - +function Board({ xIsNext, squares, onPlay }) { function handleClick(i) { if (squares[i] || calculateWinner(squares)) { return; @@ -27,8 +24,7 @@ function Board() { } else { nextSquares[i] = "O"; } - setSquares(nextSquares); - setXIsNext(!xIsNext); + onPlay(nextSquares); } const winner = calculateWinner(squares); @@ -62,10 +58,19 @@ function Board() { } function App() { + const [xIsNext, setXIsNext] = useState(true); + const [history, setHistory] = useState([Array(9).fill(null)]); + const currentSquares = history[history.length - 1]; + + function handlePlay(nextSquares) { + setHistory([...history, nextSquares]); + setXIsNext(!xIsNext); + } + return (
- +
    {/*TODO*/}