无法读取未定义的 属性 '0' - 卡在 reactjs 教程中
Cannot read property '0' of undefined - stuck with reactjs tutorial
我停留在 the tutorial 的 "Storing a history" 部分,试图将状态从 Board
拉到 Game
。我已经从 Board
中删除了构造函数并试图更改 Board
以便它需要 squares
通过 props:
renderSquare(i) {
return <Square value={this.props.squares[i]} onClick={() => this.props.onClick(i)} />;
}
但是失败了..
在您的示例中,您将正方形作为道具传递。所以你需要改变
renderSquare(i) {
return (
<Square
value={this.props.squares[i]}
onClick={() => this.props.onClick(i)}
/>;
);
}
进入
renderSquare(i) {
return (
<Square
value={this.props[i]}
onClick={() => this.props.onClick(i)}
/>;
);
}
因为this.props
已经引用了你传入的方块
我有我的应用渲染板而不是游戏,所以这就是它不工作的原因。
我停留在 the tutorial 的 "Storing a history" 部分,试图将状态从 Board
拉到 Game
。我已经从 Board
中删除了构造函数并试图更改 Board
以便它需要 squares
通过 props:
renderSquare(i) {
return <Square value={this.props.squares[i]} onClick={() => this.props.onClick(i)} />;
}
但是失败了..
在您的示例中,您将正方形作为道具传递。所以你需要改变
renderSquare(i) {
return (
<Square
value={this.props.squares[i]}
onClick={() => this.props.onClick(i)}
/>;
);
}
进入
renderSquare(i) {
return (
<Square
value={this.props[i]}
onClick={() => this.props.onClick(i)}
/>;
);
}
因为this.props
已经引用了你传入的方块
我有我的应用渲染板而不是游戏,所以这就是它不工作的原因。