Skip to content

Conversation

@trambui09
Copy link

@trambui09 trambui09 commented Dec 31, 2020

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? Event listeners call on the event handler function to be able to change the useState. For example, the onClick event triggered the function to be able to do the callback to change the value of the square in our app.
What are two ways to do "dynamic styling" with React? When should they be used? We can use ternary to set the className (externally css) or we can dynamically style with in-line css with logic/ternary again.
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. With the event listeners, it has the ability to change the state. When the state is changed, React knows to re-render the page content with the new state value.

CS Fundamentals Questions

Question Answer
What do you think is the BigO complexity of the method you use to compute a winner? We think the time and the space complexity is O(1) because we loop through only 8 winning conditions for our tic tac toe (3X3 board).
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.
In speculating wildly, we think since React is known for its efficient re-rendering from the virtual DOM to the DOM that the Big-O should be pretty efficient. We think the components are in an array, so React probably traverse it with an O(n) time complexity.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

For TicTacToe we reviewed test results, the checkForWinner function, and onClickCallback function. Both functions look good and do what's required. Good work implementing a React project using state and callback functions!

setSquares(squares)
}

const checkForWinner = () => {

Choose a reason for hiding this comment

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

👍

// You will need to create a method to change the square
// When it is clicked on.
// Then pass it into the squares as a callback
const callback = (updatedSquare) => {

Choose a reason for hiding this comment

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

👍 , but I might use a more descriptive name to illustrate what this function does.

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