componentDidCatch被多次调用

时间:2018-11-20 08:01:09

标签: reactjs

单击按钮即可渲染组件。此组件引发错误,并由Error-Boundary包装。因此,从我对文档的理解来看,应该调用Error-Boundary,并且仅应抛出一次错误。但是我注意到错误也在产品环境中多次抛出。

我的componentDidCatch看起来像:

componentDidCatch(error, info) {
  this.hasError = true;
  this.error = error;
  this.severity = this.props.severity;
}

当我在componentDidCatch内进行console.log时,它会打印约9次。

我的组件按以下方式包装:

ReactDOM.render(
 <Provider store={createStoreWithMiddleware(reducers)}>
 <ErrorBoundary severity="FATAL">
  <App />
 </ErrorBoundary>
 </Provider>, document.getElementById('root'));

应用程序是我的主要组件。 App再次呈现其他组件。

<ErrorBoundary severity="FATAL">
   <component1 />
</ErrorBoundary>

错误被显示9次。谁能帮助我理解为什么多次抛出该错误?

0 个答案:

没有答案
相关问题