admin管理员组文章数量:1387427
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.
本文标签: javascriptCannot read property 39039 of undefinedstuck with reactjs tutorialStack Overflow
版权声明:本文标题:javascript - Cannot read property '0' of undefined - stuck with reactjs tutorial - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744545873a2611893.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论