最大调用堆栈大小超过了堆- redux
16lz
2021-01-22
I have error maximum call stack size exceeded
. Maybe I in wrong way understand componentDidUpdate
, but shouldn't it's run one time, instead 1000. How fix it?
我已经超过了最大调用堆栈大小。也许我理解componentDidUpdate是错误的,但是它不应该运行一次,而应该是1000。如何修复它吗?
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
更多相关文章
- JqueryUI Draggable - 仅自动垂直调整父容器大小
- 固定大小的div不应该将数字分成两半
- 使用CSS,HTML和Javascript在随机图像的页面上进行图像大小调整
- Jquery UI draggable不会调整其他DIV的大小
- 如何获得mp3文件的大小和持续时间?
- 什么是一个很好的JS库,可以调整大小?
- req.files.upload.length返回文件计数为零,或上传多个文件,当一个
- 谷歌映射API v3: InfoWindow大小不正确
- 如何在HTML页面中维护SWF文件的大小?