I stuck at the "Storing a history" part of the tutorial, trying to pull state up from Board
to Game
. I've removed constructor from Board
and was trying to change Board
so that it takes squares
via props:
renderSquare(i) {
return <Square value={this.props.squares[i]} onClick={() => this.props.onClick(i)} />;
}
but it fails..
code:
I stuck at the "Storing a history" part of the tutorial, trying to pull state up from Board
to Game
. I've removed constructor from Board
and was trying to change Board
so that it takes squares
via props:
renderSquare(i) {
return <Square value={this.props.squares[i]} onClick={() => this.props.onClick(i)} />;
}
but it fails..
code: https://codepen.io/gka/pen/eBgapz
Share Improve this question edited Nov 21, 2016 at 10:31 Martijn Pieters 1.1m321 gold badges4.2k silver badges3.4k bronze badges asked Nov 20, 2016 at 17:04 GiedriusGiedrius 1381 silver badge8 bronze badges 02 Answers
Reset to default 5In your example, you pass in squares as props. So you need to change
renderSquare(i) {
return (
<Square
value={this.props.squares[i]}
onClick={() => this.props.onClick(i)}
/>;
);
}
into
renderSquare(i) {
return (
<Square
value={this.props[i]}
onClick={() => this.props.onClick(i)}
/>;
);
}
Because this.props
already refers to the squares you passed in.
I had my App render Board instead of Game, so that was the reason it wasn't working.