Skip to content

Commit

Permalink
refactor(react): remove state
Browse files Browse the repository at this point in the history
  • Loading branch information
budougumi0617 committed Oct 6, 2024
1 parent 3ae8dd8 commit dbfeadb
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions react/tic-tac-toe/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,15 @@ export default function Game() {
Array(9).fill(null),
]);
const [currentMove, setCurrentMove] = useState<number>(0);
const xIsNext = currentMove % 2 === 0;
const currentSquares = history[currentMove];
function handlePlay(nextSquares: Array<string | null>): void {
const nextHistory = [...history.slice(0, currentMove + 1), nextSquares];
setHistory(nextHistory);
setCurrentMove(nextHistory.length - 1);
setXIsNext(!xIsNext);
}
function jumpTo(nextMove: number): void {
setCurrentMove(nextMove);
setXIsNext(nextMove % 2 === 0);
}

const moves = history.map((squares: Array<string | null>, move: number) => {
Expand Down

0 comments on commit dbfeadb

Please sign in to comment.