/** React error boundary that catches render-time exceptions and shows a * recoverable error UI instead of a white screen. */ import * as React from "react"; interface Props { children: React.ReactNode; } interface State { error: Error | null; } /** Catches uncaught render exceptions in its subtree and displays a message. */ export class ErrorBoundary extends React.Component { constructor(props: Props) { super(props); this.state = { error: null }; } static getDerivedStateFromError(error: Error): State { return { error }; } handleReset = () => { this.setState({ error: null }); }; render() { if (this.state.error) { return (
Something went wrong
{this.state.error.message}
); } return this.props.children; } }