clean up
This commit is contained in:
parent
cba59847bf
commit
084c254386
@ -58,22 +58,20 @@ function Board({ xIsNext, squares, onPlay }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [xIsNext, setXIsNext] = useState(true);
|
|
||||||
const [history, setHistory] = useState([Array(9).fill(null)]);
|
const [history, setHistory] = useState([Array(9).fill(null)]);
|
||||||
const [currentMove, setCurrentMove] = useState(0);
|
const [currentMove, setCurrentMove] = useState(0);
|
||||||
|
const xIsNext = currentMove % 2 === 0;
|
||||||
const currentSquares = history[currentMove];
|
const currentSquares = history[currentMove];
|
||||||
|
|
||||||
function handlePlay(nextSquares) {
|
function handlePlay(nextSquares) {
|
||||||
const nextHistory = [...history.slice(0, currentMove + 1), nextSquares];
|
const nextHistory = [...history.slice(0, currentMove + 1), nextSquares];
|
||||||
setHistory(nextHistory);
|
setHistory(nextHistory);
|
||||||
setCurrentMove(nextHistory.length - 1);
|
setCurrentMove(nextHistory.length - 1);
|
||||||
setXIsNext(!xIsNext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function jumpTo(nextMove) {
|
function jumpTo(nextMove) {
|
||||||
setCurrentMove(nextMove);
|
setCurrentMove(nextMove);
|
||||||
setHistory(history.slice(0, nextMove+1));
|
setHistory(history.slice(0, nextMove+1));
|
||||||
setXIsNext(nextMove % 2 === 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const moves = history.map((squares, move) => {
|
const moves = history.map((squares, move) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user