Skip to content

timeTravel done, not classed based#7

Open
CieloRaymundo wants to merge 1 commit intoThe-Marcy-Lab-School:masterfrom
CieloRaymundo:master
Open

timeTravel done, not classed based#7
CieloRaymundo wants to merge 1 commit intoThe-Marcy-Lab-School:masterfrom
CieloRaymundo:master

Conversation

@CieloRaymundo
Copy link

No description provided.

setBoardState(boardInHistory[step]);
}

function goToStart() {
Copy link

Choose a reason for hiding this comment

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

👍 - this is a neat feature. Nice work including this!

Copy link

@ipc103 ipc103 left a comment

Choose a reason for hiding this comment

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

Hey @CieloRaymundo - really nice work on this one! I left you some comments in line - the biggest thing to take a look at would be what type of data you're storing in the stages array. Otherwise, I left a few comments around what other stuff you might be able to include on the context you created. Feel free to respond if you have any other questions, but overall nice job!


return (
<div className="board">
<div className="rows">
Copy link

Choose a reason for hiding this comment

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

One trick for handling stuff like this is to use the chunk method from lodash to split your array into three groups. You can then map over the result and render a row for each group. https://lodash.com/docs/4.17.15#chunk

{_.chunk(board, 3).map(row => (
  <div className="row board-row">{row.map((cell, i) => <Square onClick={() => clickHandler(i)} value={cell} }</div>
))}

return (
<div>
<h1>It's your turn player {turn}</h1>
<TurnContext.Provider value={turn}>
Copy link

Choose a reason for hiding this comment

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

It's cool that you used a context here, because it demonstrates knowledge of different React hooks. Nice work! One thing to think about is - when you're making a context, it might make sense to group related pieces of data together. For this one, I'd probably include a bunch of the game data on the context so that it is all in one place. This could include:

  1. The board
  2. The current player
  3. The history of the board
  4. Whether or not we have a winner
  5. A function for the current player to take their turn

You have all of that stuff in your app, but it's just spread out. Keeping it all in the context could help keep the components a little bit smaller.

import React from 'react';
import './style.css';

function Squares(props) {
Copy link

Choose a reason for hiding this comment

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

One small thing - you can use object destructuring here if you like to avoid needing to call props. multiple times.

function Square({click, value})

import './style.css';
import Board from './Board';

export const TurnContext = React.createContext();
Copy link

Choose a reason for hiding this comment

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

One other note - you can include multiple pieces of state on a single context, so I'd probably group both the turn and the setTurn function onto one TurnContext instead of separating them out.

const desc = `Go to move #${stage+1}`;
return (
<li key={stage}>
<button onClick={() => moveToStage(stage)}>{desc}</button>
Copy link

Choose a reason for hiding this comment

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

This seems to be where the bug in the time travel is coming from. What does your stages array look like here? Once you confirm that, I bet you will be able to debug this :-)

@ipc103 ipc103 removed their assignment Apr 19, 2021
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