Skip to content

Conversation

@ubeninja77
Copy link

React Tic Tac Toe

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

Reflection

Prompt Response
How are events / event handlers and useState connected? useState and event handlers are connected through a callback functions.
What are two ways to do "dynamic styling" with React? When should they be used? Through React you can use inline styling using the built in style attribute. Or you can use a linked style sheet using classNames.
Much like Rails works with the HTTP request->response cycle, React works with the browser's input->output cycle. Describe React's cycle from receiving user input to outputting different page content. The program is updated when an event occurs, a callback function is triggered. When a state is changed, React runs a code and renders the components.

CS Fundamentals Questions

Question Answer
What do you think is the BigO complexity of the method you use to compute a winner? 0n and 0(1)
Consider what happens when React processes a state change from setState -- it must re-render all of the components that now have different content because of that change.
What kind of data structure are the components in, and what sort of algorithms would be appropriate for React's code to "traverse" those components?
Speculate wildly about what the Big-O time complexity of that code might be.
The components adopt a tree structure. My guess is since the data remains the same, O(1). ???But if the state is different than before, the tree will change and the time complexity would as well???

@CheezItMan
Copy link

React Tic Tac Toe

Major Learning Goals/Code Review

Criteria yes/no, and optionally any details/lines of code to reference
Demonstrates proper JavaScript coding style. ✔️
Correctly passes props to child components. ✔️
Correctly passes callback functions to child components and calls them to respond to user events.) ✔️
Maintains the status of the game in state. ✔️
Practices git with at least 6 small commits and meaningful commit messages ✔️, you have 9 commits, but you use waves as commit messages, I suggest you instead describe the functionality you added.
Uses existing stylesheets to render components ✔️

Functional Requirements

Functional Requirement yes/no
The Square component renders properly and executes the callback on a click event. ✔️
The Board component renders a collection of squares ✔️
The App component renders a board and uses state to maintain the status of the game. ✔️
Utilizes callbacks to UI events to update state ✔️

Overall Feedback

Overall Feedback Criteria yes/no
Green (Meets/Exceeds Standards) 5+ in Code Review && 3+ in Functional Requirements

Code Style Bonus Awards

Was the code particularly impressive in code style for any of these reasons (or more...?)

Quality Yes?
Perfect Indentation
Elegant/Clever
Descriptive/Readable
Concise
Logical/Organized

Summary

Well done, you hit the learning goals here. This is is a very solid submission here. Excellent work!

// When it is clicked on.
// Then pass it into the squares as a callback
const onClickCallback = (id) => {
if (winner === "PLAYER_1" || winner === "PLAYER_2") return

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 quite working as when the player wins you can keep clicking.

Suggested change
if (winner === "PLAYER_1" || winner === "PLAYER_2") return
if (winner !== null) return

Comment on lines +76 to +77
squares.map(row =>
row.map(square => (

Choose a reason for hiding this comment

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

Instead of using .map here, I'd use forEach since you're not converting the squares array into something else.

Comment on lines +7 to +10
//https://www.udemy.com/course/reactjs-tic-tac-toe-game-in-30-minutes/
//https://scrimba.com/c/cbqm3SM
//https://reactjs.org/tutorial/tutorial.html

Choose a reason for hiding this comment

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

Thanks for documenting.

Comment on lines +83 to +88
for (let line of winningCombinations) {
if (newSquare[line[0]] === newSquare[line[1]] && newSquare[line[0]] === newSquare[line[2]] && newSquare[line[0]] !== '') {
console.log(newSquare[line[0]]);
return newSquare[line[0]];
}
}

Choose a reason for hiding this comment

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

I like this solution.

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