【发布时间】:2017-11-08 22:11:52
【问题描述】:
我收到了
错误:“未捕获的 RangeError:超出最大调用堆栈大小”
我怀疑我的 componentWillUpdate 方法中的这段代码是原因,因为我只是在添加代码后才收到错误。我在这里做错了什么吗?
componentWillUpdate(nextProps, nextState) {
...
if (nextProps.show) {
for (var i = 0; i < this.props.data.actions.length; i++) {
if (this.props.data.actions[i].assignedTo !== this.state.userId && this.state.showActions === true) {
this.setState({ showActions: false })
}
if (this.props.data.actions[i].assignedTo === this.state.userId && this.state.showActions === false) {
this.setState({ showActions: true })
}
}
}
...
}
nextProps.show 在单击按钮时设置为 true,然后检查分配操作的人员是否与登录的用户相同,然后将状态 showActions 设置为 true。此状态用于在满足代码中的条件时显示/隐藏行
【问题讨论】:
-
这意味着在您的代码中的某个地方,您正在调用一个函数,该函数又调用另一个函数,依此类推,直到您达到调用堆栈限制。如所述stackoverflow.com/questions/6095530/…
标签: javascript reactjs