@khazh/tic-tac-toe-react
Version:
A customizable Tic Tac Toe game component for React with AI opponent, configurable board size, and win conditions
27 lines • 742 B
JavaScript
import { useState } from "react";
export const useScore = () => {
const [score, setScore] = useState({ X: 0, O: 0, draws: 0 });
const updateScore = (winner, isDraw) => {
if (winner || isDraw) {
setScore((prev) => ({
...prev,
...(winner
? { [winner]: prev[winner] + 1 }
: { draws: prev.draws + 1 }),
}));
}
};
const resetScore = () => {
setScore({ X: 0, O: 0, draws: 0 });
};
const getTotalGames = () => {
return score.X + score.O + score.draws;
};
return {
score,
updateScore,
resetScore,
getTotalGames,
};
};
//# sourceMappingURL=useScore.js.map