import React from "react"; interface IErrorBoundaryProps { children?: React.ReactNode; } type ErrorInfo = { componentStack: string; }; interface IErrorBoundaryState { error?: Error; errorInfo?: ErrorInfo; } export class ErrorBoundary extends React.Component< IErrorBoundaryProps, IErrorBoundaryState > { constructor(props: IErrorBoundaryProps) { super(props); this.state = {}; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { this.setState({ error, errorInfo, }); } public render() { if (this.state.errorInfo) { // Error path return (

Something went wrong.

{this.state.error && this.state.error.toString()}
{this.state.errorInfo.componentStack}
); } // Normally, just render children return this.props.children; } }