A simple and clean Tic Tac Toe game built with React and TypeScript. This project is designed for teaching and practicing the fundamentals of:
- useState
- useEffect (later - for the turn timer)
- Component structure
- State flow between parent/child components
- Clone the repository
git clone https://github.com/your-username/tic-tac-toe-react.git
cd tic-tac-toe-react- Install dependencies
npm install- Start the development server
npm run devYour app should be running at:
http://localhost:5173- useState for managing UI state
- Data flow between parent and child components
- Component reusability (Board/Square)
- Grid rendering using .map()
- Event handling in React
- useEffect for timers and side effects
- Adding game logic & winner detection
- Managing more complex state
Goal: When clicking a square, place "X" or "O" depending on whose turn it is. Hints:
- Use the existing isXNext state
- Update the squares array with the new value
- Toggle the turn after each move
Goal: When a player gets 3 in a row, display a winner message. Hints:
- Check
squares[index] !== nullbefore updating
Goal: When a player gets 3 in a row, display a winner message. Hints:
- Create a
calculateWinner()helper - Use all 8 winning combinations
- Add a winner:
string | nullstate in Game
Goal: Disable the board after someone wins. Hints:
- If there's a winner → ignore clicks
- Or disable the buttons with disabled attribute
Goal: Disable the board after someone wins. Hints:
- Clear squares back to
Array(9).fill(null) - Reset
isXNext→ true
Goal: Each player gets e.g. 10 seconds to play. If time runs out → automatically switch turn. Hints:
- Create
timeLeftstate - Use
useEffectwithsetInterval - Reset timer on every turn change
- Cleanup the interval on unmount or turn switch