Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed files to use, pushed up working game #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Deteriator
Copy link

No description provided.

display: table;
}

.status {
Copy link

@Keyairra-S-Wright Keyairra-S-Wright May 2, 2020

Choose a reason for hiding this comment

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

Looks like this status style isn't used in the app. If that's the case, then this can be removed.

outline: none;
}

.kbd-navigation .square:focus {
Copy link

@Keyairra-S-Wright Keyairra-S-Wright May 2, 2020

Choose a reason for hiding this comment

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

Keyboard navigation styles is classy. I am not familiar with this implementation. How does this work in the app?

import "./index.css";
import * as serviceWorker from './serviceWorker';

function Square({ value, onClick }) {

Choose a reason for hiding this comment

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

There are several components here in index.jsx. In order to organize your code in a more modular way, I'd recommend separating out this file by component (ie could go into a "Square.jsx" file and could go into a "Game.jsx" file, etc). By having logical chunks of code, this app will become more accessible and easier for other developers to reason about.

Comment on lines +17 to +24
function Restart({ onClick }) {

return (
<button className="restart" onClick={onClick}>
Play again
</button>
);
}
Copy link

@Keyairra-S-Wright Keyairra-S-Wright May 3, 2020

Choose a reason for hiding this comment

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

The creation and use of this <Restart/> component is groovy and allows for a an intuitive user experience. 👍

Comment on lines +75 to +87
{renderSquare(0)}
{renderSquare(1)}
{renderSquare(2)}
</div>
<div className="board-row">
{renderSquare(3)}
{renderSquare(4)}
{renderSquare(5)}
</div>
<div className="board-row">
{renderSquare(6)}
{renderSquare(7)}
{renderSquare(8)}

Choose a reason for hiding this comment

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

Separating out the logic of rendering a square helped reduce code repetition and makes this part of the code easier to reason about. 👍 To take this a step further, this could refactored by mapping through the squares. That would mean, however, that the styles for these rows would need updating.

Comment on lines +48 to +55
if (squares[i] != null || winner != null) {
return;
}
const nextSquares = squares.slice();
nextSquares[i] = (isXNext ? "X" : "O");
setSquares(nextSquares);

setIsXNext(!isXNext); // toggle turns

Choose a reason for hiding this comment

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

Consider extracting this logic into it's on click handler function.

[0, 4, 8],
[2, 4, 6]
];
// go over all possibly winning lines and check if they consist of only X's/only O's

Choose a reason for hiding this comment

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

The inline code comments for this function are helpful for other developers to get a quick grasp of how these utility functions are used. 👍

function Game() {
const [ squares, setSquares ] = useState(Array(9).fill(null));
const [ isXNext, setIsXNext ] = useState(true);
const nextSymbol = isXNext ? "X" : "O";

Choose a reason for hiding this comment

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

It was wise to place this ternary statement in a variable. 👍 . Since nextSymbol is defined, it can be used down on lines 52 and 66.

);
}

ReactDOM.render(<Square />, document.getElementById("root"));
Copy link

@Keyairra-S-Wright Keyairra-S-Wright May 3, 2020

Choose a reason for hiding this comment

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

Since the <Game/> component renders the instances of the <Square/>, this component does not require its own render.

ReactDOM.render() docs states If the React element was previously rendered into container, this will perform an update on it and only mutate the DOM as necessary to reflect the latest React element.

This means that ReactDOM.render() is updated by the ReactDOM.render() on line 126. If this line remained without line 126, then the app would render only one instance of the <Square/> component.

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