如何解决即使使用错误边界后,浏览器错误窗口也会出现
在我的 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 举报,一经查实,本站将立刻删除。