import React from "react"; export interface PageErrorBoundaryProps { errorPage: React.ComponentType<{ error: T }>; children: React.ReactNode; } export default class PageErrorBoundary extends React.Component< PageErrorBoundaryProps > { state: { error: T | null } = { error: null }; errorPage: PageErrorBoundaryProps["errorPage"]; constructor(props: PageErrorBoundaryProps) { super(props); this.errorPage = props.errorPage; } componentDidCatch(error: Error) { this.setState({ error }); } render() { const { error } = this.state; if (error) { const ErrorPage = this.errorPage; return ; } return this.props.children; } }