エラーmaximum call stack size exceeded
があります。多分私は間違った方法でcomponentDidUpdate
を理解していますが、それは1000回ではなく、一度実行してはいけません。呼び出しスタックの最大サイズを超えました。React-Redux
class App extends Component {
constructor(props) {
super(props);
this.state = {
amount: 0
}
}
updateAmout() {
let number = 0;
this.props.comments.map((comment, index) => {
if (comment.replyTo === null) {
number += 1;
this.setState({amount: number});
}
return null;
});
}
componentWillMount() {
this.updateAmout();
}
componentDidUpdate() {
this.updateAmout();
}
render() {
console.log(this.state.amount);
return (
<div className="comments-container">
<div id="comments">
<AddComment />
<div className="comments-flow">
<div className="comments-header">
<div className="pull-right">
<a href="" className="text-muted">Best</a> |
<a href="" className="active">Newest</a> |
<a href="" className="text-muted">Oldest</a>
</div>
<b>6 Comments</b>
</div>
<RenderComments />
</div>
<button className="btn btn-block">More...</button>
</div>
</div>
) // return
} // render
} // App
'componentWillMount'は'ように再度更新を強制し、あろうcomponentDidUpdate'をトリガする更新を強制します。 – MinusFour
'componentDidUpdate()'は状態更新が正常に終了したことを通知するためのコールバックです。ここで別の状態の更新をトリガーするべきではありません。 –