From f11140a0a6c6154eac21029606fec292fb3edfa8 Mon Sep 17 00:00:00 2001
From: Dan Abramov
In the development mode, you can visualize how components mount, update, and unmount, using the performance tools in supported browsers. For example:
-

To do this in Chrome:
@@ -251,7 +251,7 @@ This section is only relevant if you configure Webpack directly.Here's a subtree of components. For each one, SCU indicates what shouldComponentUpdate returned, and vDOMEq indicates whether the rendered React elements were equivalent. Finally, the circle's color indicates whether the component had to be reconciled or not.


Since shouldComponentUpdate returned false for the subtree rooted at C2, React did not attempt to render C2, and thus didn't even have to invoke shouldComponentUpdate on C4 and C5.
You can call it in Board's render function to check if anyone has won the game and make the status text show "Winner: [X/O]" when someone wins:
You can call it in Board's render function to check if anyone has won the game and make the status text show "Winner: [X/O]" when someone wins.
Replace the status declaration in Board's render with this code:
render() {
const winner = calculateWinner(this.state.squares);
let status;
@@ -886,8 +891,17 @@
}
render() {
+ const winner = calculateWinner(this.state.squares);
+ let status;
+ if (winner) {
+ status = 'Winner: ' + winner;
+ } else {
+ status = 'Next player: ' + (this.state.xIsNext ? 'X' : 'O');
+ }
+
return (
<div>
+ <div className="status">{status}</div>
<div className="board-row">
{this.renderSquare(0)}
{this.renderSquare(1)}
@@ -940,9 +954,9 @@
Since Game is now rendering the status, we can delete <div className="status">{status}</div> and the code calculating the status from the Board's render function:
render() {
return (
- <div>
- <div className="board-row">
- {this.renderSquare(0)}
+ <div>
+ <div className="board-row">
+ {this.renderSquare(0)}
{this.renderSquare(1)}
{this.renderSquare(2)}
</div>