Skip to content

Conversation

@AxelrodAsaf
Copy link

Completion of tasks:
1 — Make the Squares Clickable
2 — Prevent Overwriting Moves
3 — Add Winner Detection
4 — Stop Moves After Win
5 — Add a “Play Again” Button
6 — Add a Turn Countdown Timer

@ShirYahav ShirYahav requested a review from OfekSagiv December 17, 2025 08:50
Comment on lines +8 to +10

const timeLimit = 10;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move constants like 'timeLimit' outside the component.
Defining it inside causes it to be re-initialized on every render,

const timeLimit = 10;

const [isXNext, setIsXNext] = useState(true);
const [winner, setWinner] = useState<string | null>(null);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need a separate state for 'winner' because it can be calculated directly from the 'squares' array during render. Storing it in state can lead to synchronization bugs.

Comment on lines +16 to +34
useEffect(() => {
if (!timeRunning || winner) return;

const timerId = window.setInterval(() => {
setTime((currTime) => Math.max(currTime - 1, 0));
}, 1000);

return () => window.clearInterval(timerId);
}, [timeRunning, winner]);

useEffect(() => {
if (!timeRunning || winner) return;

if (time === 0) {
setIsXNext((currPlayer) => !currPlayer);
setTime(timeLimit);
}
}, [time, timeRunning, winner, timeLimit]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have two separate UseEffects monitoring the timer. This can cause race conditions where the timer ticks to 0 but the logic to switch players doesn't trigger until the next render cycle.

Comment on lines +95 to +99
{winner == null
? isXNext
? "Next Player: X"
: "Next Player: O"
: null}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid nested ternary operators in the return block. Calculate a 'status' string before the return statement and just display {status} here.

</button>
);
}
export const Square = ({ value, onClickFunction }: SquareProps) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using both a Named Export (export const) and a Default Export at the bottom. It's better to stick to one.

@OfekSagiv
Copy link

There is an issue between your Parent (Board) and Child (Square) components.
Square expects a prop named onClickFunction, but Board is trying to pass it as onClick.
The child component receives undefined, so the click handler will never fire.

Check both files and ensure the names match exactly in the interface and the component usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants