【发布时间】:2019-10-17 05:55:47
【问题描述】:
我正在尝试在函数完成后设置状态,但出现错误:
Uncaught Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
我在函数完成后在回调中调用 setstate,所以我认为从我读过的内容来看这可以正常工作,但我似乎无法让它工作。
组件更新时运行addStuff函数
componentDidUpdate() {
this.addStuff(() => this.setState({"loading":false}))
}
完成时设置回调
addStuff(callback) {
...Does a bunch of stuff
callback();
}
谁能建议我在这里做错了什么?谢谢。
【问题讨论】:
-
不,在应用状态下默认是真的
标签: javascript reactjs