Skip to content

Commit 5695711

Browse files
committed
2nd step: Add game history.
1 parent 5755e5e commit 5695711

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ class Game extends React.Component {
3838
this.current = this.history[this.history.length-1];
3939
this.winner = calculateWinner(this.current.squares); // Due Game Component now have the squares state this Component will calculateWinner.
4040

41+
const moves = this.history.map((step, move) => {
42+
const desc = move ? 'Go to move #' + move : 'Go to game start';
43+
return (
44+
<li>
45+
<button onClick={() => this.jumpTo(move)}>{desc}</button>
46+
</li>
47+
);
48+
});
49+
4150
let status;
4251
if (this.winner) {
4352
status = 'Winner: ' + this.winner;
@@ -55,6 +64,7 @@ class Game extends React.Component {
5564
</div>
5665
<div className="game-info">
5766
<div>{status}</div>
67+
<ol>{moves}</ol>
5868
</div>
5969
</div>
6070
);

0 commit comments

Comments
 (0)