File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed
Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -2,17 +2,16 @@ import React from 'react';
22import ReactDOM from 'react-dom' ;
33import './index.css' ;
44
5- class Square extends React . Component {
5+ function Square ( props ) {
66
7- render ( ) {
87 return (
98 < button className = "square"
10- onClick = { ( ) => this . props . onClick ( ) }
9+ onClick = { props . onClick }
1110 >
12- { this . props . value }
11+ { props . value }
1312 </ button >
1413 ) ;
15- }
14+
1615 }
1716
1817 class Board extends React . Component {
@@ -21,13 +20,17 @@ class Square extends React.Component {
2120 super ( props ) ;
2221 this . state = {
2322 squares : Array ( 9 ) . fill ( null ) ,
23+ xIsNext :true ,
2424 }
2525 }
2626
2727 handleClick ( i ) {
2828 const squares = this . state . squares . slice ( ) ;
29- squares [ i ] = 'X' ;
30- this . setState ( { squares :squares } ) ;
29+ squares [ i ] = this . state . xIsNext ?'X' :'O' ;
30+ this . setState ( {
31+ squares :squares ,
32+ xIsNext :! this . state . xIsNext ,
33+ } ) ;
3134 }
3235 renderSquare ( i ) {
3336 return (
@@ -39,7 +42,7 @@ class Square extends React.Component {
3942 }
4043
4144 render ( ) {
42- const status = 'Next player: X' ;
45+ const status = 'Next player: ' + ( this . state . xIsNext ? 'X' : 'O' ) ;
4346
4447 return (
4548 < div >
You can’t perform that action at this time.
0 commit comments