我一直在尝试解决以下错误,但无法找到实际原因。我经历了所有与类似错误相关的解决方案,但没有一个回答我的问题。
有人可以帮我吗?
Uncaught Error: 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.
at invariant (react-dom.development.js:57)
at scheduleWork (react-dom.development.js:20921)
at Object.enqueueSetState (react-dom.development.js:11596)
at Router.push../node_modules/react/cjs/react.development.js.Component.setState (react.development.js:336)
at react-router.js:60
at listener (history.js:162)
at history.js:180
at Array.forEach (<anonymous>)
at Object.notifyListeners (history.js:179)
at setState (history.js:300)
at history.js:414
at Object.confirmTransitionTo (history.js:152)
at replace (history.js:397)
at Lifecycle.onMount (react-router.js:290)
at Lifecycle.componentDidMount (react-router.js:174)
at Lifecycle.componentDidMount (react-hot-loader.development.js:652)
at commitLifeCycles (react-dom.development.js:18115)
at commitAllLifeCycles (react-dom.development.js:19674)
at HTMLUnknownElement.callCallback (react-dom.development.js:147)
at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
at invokeGuardedCallback (react-dom.development.js:250)
at commitRoot (react-dom.development.js:19898)
at react-dom.development.js:21446
at Object.unstable_runWithPriority (scheduler.development.js:255)
at completeRoot (react-dom.development.js:21445)
at performWorkOnRoot (react-dom.development.js:21368)
at performWork (react-dom.development.js:21273)
at performSyncWork (react-dom.development.js:21247)
at requestWork (react-dom.development.js:21102)
at scheduleWork (react-dom.development.js:20915)
at scheduleRootUpdate (react-dom.development.js:21610)
at updateContainerAtExpirationTime (react-dom.development.js:21636)
at updateContainer (react-dom.development.js:21704)
at ReactRoot.push../node_modules/react-dom/cjs/react-dom.development.js.ReactRoot.render (react-dom.development.js:22017)
at react-dom.development.js:22169
at unbatchedUpdates (react-dom.development.js:21492)
at legacyRenderSubtreeIntoContainer (react-dom.development.js:22165)
at Object.render (react-dom.development.js:22240)
at render (index.js:11)
at Module../src/index.js (index.js:25)
at __webpack_require__ (bootstrap:781)
at fn (bootstrap:149)
at Object.0 (helpers.js:20)
at __webpack_require__ (bootstrap:781)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.chunk.js:1
答案 0 :(得分:1)
不要害怕阅读错误消息。在第一个字符串中,React试图给出提示。
已超过最大更新深度。当组件重复调用componentWillUpdate或componentDidUpdate内部的setState时,可能会发生这种情况。 React限制了嵌套更新的数量,以防止无限循环。
仔细查看您的代码,不要害怕阅读错误消息或文档。 祝你好运:)
答案 1 :(得分:1)
您是否触发onclick事件? 我遇到了类似的错误,并使用箭头函数而非标准调用对其进行了修复
<button type="button" onClick={() => this.example()}>test</button>
请发布您的代码