问题描述
在我的 React 应用程序中,我添加了 React Boundary, 但是当我的任何组件出现任何错误时,
我得到错误边界组件一秒钟,然后弹出默认的 chrome 错误窗口。 我必须关闭错误窗口才能看到我的 React 应用程序。
我没有看到任何解决方案。有没有人遇到同样的问题,或者我遗漏了什么?
export default class ErrorBoundary extends React.Component {
state = { hasError: false };
static getDerivedStateFromError(error) {
// Update state so the next render will show the fallback UI.
console.log('getDerivedStateFromError: Error Occurred while loading component');
console.log({ error });
return { hasError: true };
}
componentDidCatch(error,errorInfo) {
// You can also log the error to an error reporting service
console.log('componentDidCatch: Error Occurred while loading component');
console.log({ error,errorInfo });
}
render() {
if (this.state.hasError) {
// You can render any custom fallback UI
return (
<h5
className="error-"
onClick={() => {
window.location.reload();
}}
>
Something not right.
</h5>
);
}
return this.props.children;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)