You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
655 B
TypeScript

import * as React from 'react';
class ErrorBoundary extends React.Component {
state: {
error?: Error;
};
constructor(props: any) {
super(props);
this.state = { };
}
componentDidCatch(error: Error, info: any) {
this.setState({ error });
}
render() {
if (this.state.error) {
return (
<div>
<h2>Something went wrong!</h2>
<pre>
{this.state.error.message}
</pre>
<h3>Stack trace:</h3>
<pre>
{this.state.error.stack}
</pre>
</div>
);
}
return this.props.children;
}
}
export default ErrorBoundary;