У меня есть этот компонент. Внутри componentDidMount
я создал объект и пытаюсь выбросить ошибку. Но мой componentDidCatch
не был вызван, а вместо этого разбивает мою страницу!
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>)
}
}