File tree 1 file changed +22
-3
lines changed 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,12 @@ class Board extends React.Component {
26
26
}
27
27
28
28
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
+ ) ;
30
35
}
31
36
32
37
render ( ) {
@@ -67,9 +72,23 @@ class Square extends React.Component {
67
72
return (
68
73
< button
69
74
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.
71
76
>
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
+ * */ }
73
92
</ button >
74
93
) ;
75
94
}
You can’t perform that action at this time.
0 commit comments