Skip to content

Commit f1c64d3

Browse files
committed
2nd step: Handle Square clickEvents by Board Component.
1 parent 10b0dc9 commit f1c64d3

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/index.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ class Board extends React.Component {
2626
}
2727

2828
renderSquare(i) {
29-
return <Square value={this.state.squares[i]} />; // Board know Squares initial state so we can define it.
29+
return (
30+
<Square
31+
value={this.state.squares[i]} // Set the 'this.props.value' of the Square Component to 'X', 'O' or Null.
32+
onClick={() => this.handleClick(i)} // Function defined by Board Component to help us to update Board state without privacity problems.
33+
/>
34+
);
3035
}
3136

3237
render() {
@@ -67,9 +72,23 @@ class Square extends React.Component {
6772
return (
6873
<button
6974
className="square"
70-
onClick={() => this.setState({value: 'X'})}
75+
onClick={() => this.props.onClick()} // onClick() will generate a 'click event' handled by handleClick() function in Board Component.
7176
>
72-
{this.state.value}
77+
{this.props.value} {/* Now we are interessed in work with 'this.props.value' due to be updated by the BoardComponent
78+
*
79+
* Explication:
80+
* · State:
81+
* - Individual local states.
82+
* - Often become the props of the Child Components.
83+
* - Inmutable (by any other Component)
84+
* - Mutable (by the same Component)
85+
*
86+
* · Props:
87+
* - External given stats.
88+
* - Always given by a Parent Component.
89+
* - Inmutable (by the same or other components)
90+
* - Mutable (by the Parent Component) <- We want this data flow
91+
* */}
7392
</button>
7493
);
7594
}

0 commit comments

Comments
 (0)