import ErrorCard from "@core/ui/reporter/components/ErrorCard"; import { React } from "@metro/common"; import { ThemeContext } from "@ui/styles"; import { Falsy } from "react-native"; type ErrorBoundaryState = { hasErr: false; } | { hasErr: true; error: Error; }; export interface ErrorBoundaryProps { children: JSX.Element | Falsy | (JSX.Element | Falsy)[]; } export default class ErrorBoundary extends React.Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasErr: false }; } static contextType = ThemeContext; static getDerivedStateFromError = (error: Error) => ({ hasErr: true, error }); render() { if (!this.state.hasErr) return this.props.children; return ( this.setState({ hasErr: false })} /> ); } }