import React, { Component } from 'react'; interface ErrorBoundaryProps { children: React.ReactNode; } interface ErrorBoundaryState { hasError: boolean; error: Error; errorInfo: React.ErrorInfo; } export default class ErrorBoundary extends Component { // In case the app crashes this component will restart it in 10 seconds // It will also print an obnoxious error message (useful for end users to grab a screenshot and report) constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false, error: { name: '', message: '' }, errorInfo: { componentStack: '' }, }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void { console.error(error, errorInfo); this.setState({ hasError: true, error, errorInfo }); setTimeout(() => { window.location.reload(); }, 30000); } render(): React.ReactNode { if (this.state.hasError) { return (

Something is borked! Restarting app in 30 seconds...

Error: {this.state.error.name}

Error message: {this.state.error.message}

Error cause: {this.state.error.cause}

Error component stack: {this.state.errorInfo.componentStack}

); } return this.props.children; } }