Skip to content

Conversation

@copelandhouse2
Copy link
Owner

Tic Tac Toe... take 3

  • Building it in React.
  • Goal of lesson... learning React

Copy link

@reneemeyer reneemeyer left a comment

Choose a reason for hiding this comment

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

Craig, nice job, just a couple questions. I would be extremely careful about storing values outside of the state. It is possible, but it should only be used in edge cases, the reason being, your react components will update on state or prop change they won't necessarily on a property change. We can go over some ideas about how you would avoid this.

state[cell] = this.state.turn;
// console.log('value of checkForWin', this.checkForWin(state));
if (this.checkForWin(state)) { //checkForWin returns TRUE if someone won. It returns FALSE if no win yet.
this.message = `Congratulations ${this.state.turn}. You won! Start a new game by refreshing`;

Choose a reason for hiding this comment

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

Why are you storing message in a class global instead of the state?

this.state = {
turn: 'X',
};
this.initialState = {

Choose a reason for hiding this comment

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

This doesn't seem to be used anywhere...

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.

3 participants