Skip to content

Spruce - Ngozi Amaefule#74

Open
ngoziamaefule wants to merge 9 commits intoAda-C16:mainfrom
ngoziamaefule:digital-starter
Open

Spruce - Ngozi Amaefule#74
ngoziamaefule wants to merge 9 commits intoAda-C16:mainfrom
ngoziamaefule:digital-starter

Conversation

@ngoziamaefule
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@audreyandoy audreyandoy left a comment

Choose a reason for hiding this comment

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

Great work Ngozi! You met all the learnings goals and passed the tests for this project.

I added ways to refactor and other approaches in your PR.

Keep up the great work!

Project Grade: 🟢

Comment thread .eslintrc.json
"plugin:react/recommended",
"plugin:jsx-a11y/recommended",
"plugin:react-hooks/recommended",
"plugin:jest/recommended",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I assume jest was removed from VS Code because it was running tests with every change right?

We actually turn off auto run by adding the key-value pair to our settings.json in VS Code:

"jest.autoRun": "off"

Comment thread src/App.js
// Then pass it into the squares as a callback

const onClickSquare = (id) => {
console.log(id);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When pushing code to be reviewed, we should eliminate any print statements or console logs.

Suggested change
console.log(id);

Comment thread src/App.js

const onClickSquare = (id) => {
console.log(id);
const newSquares = [...squares];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job in making a copy of the squares data! Here's a reminder on why we need to make the copy:

To trigger the update stage for this component, React needs to notice a change in state data. We could mutate state directly, however, this doesn't scale well and doesn't follow React best practices.

Instead, we should pass in a copy of our state data to the setState function setSquares() which will have React compare the object references between the copy and the old state data. If the object references are different, React will then trigger the update stage.

Comment thread src/App.js
const onClickSquare = (id) => {
console.log(id);
const newSquares = [...squares];
if (checkForWinner() === null) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The ! (not) operator can also be used to check if a value is falsy

Suggested change
if (checkForWinner() === null) {
if (!checkForWinner()) {

Comment thread src/App.js
Comment on lines +55 to +59
if (currentPlayer === Player1) {
setCurrentPlayer(Player2);
} else {
setCurrentPlayer(Player1);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We can use a ternary operator to set the currentPlayer:

Suggested change
if (currentPlayer === Player1) {
setCurrentPlayer(Player2);
} else {
setCurrentPlayer(Player1);
}
setCurrentPlayer(currentPlayer === PLAYER_1 ? PLAYER_2 : PLAYER_1;

Comment thread src/components/Square.js
Comment on lines 6 to +20
const Square = (props) => {
// For Wave 1 enable this
// Component to alert a parent
// For Wave 1 enable this
// Component to alert a parent
// component when it's clicked on.
const clickHandler = (e) => {
e.preventDefault();
props.onClickCallback(props.id);
};

return <button
className="square"
>
{props.value}
</button>
}
return (
<button className="square" onClick={clickHandler}>
{props.value}
</button>
);
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We could use object destructuring to reference prop data by their key name instead.

const Square = ( {value, id, onClickCallback, key} ) => {
  const clickHandler = (e) => {
    e.preventDefault();
    onClickCallback(id);
  };

  return (
    <button className="square" onClick={clickHandler}>
      {value}
    </button>
  );

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