我有这个组件。在里面componentDidMount
我创建了一个对象并尝试抛出错误。但是 mycomponentDidCatch
没有被调用反而破坏了我的页面!
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = {
error: null,
errorInfo: null
};
}
componentDidCatch(error, errorInfo) {
// Catch errors in any child components and re-renders with an error message
this.setState({
error,
errorInfo
});
console.log({ error, errorInfo });
}
componentDidMount() {
const d = {}
console.log(d.d.d)
}
render() {
console.log("458454545454")
if (this.state.error) {
console.log("Error occurred")
}
return(<div>dffdfdfdfdfd</div>)
}
}