| 9 | } |
| 10 | |
| 11 | export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> { |
| 12 | constructor(props: ErrorBoundaryProps) { |
| 13 | super(props); |
| 14 | this.state = { hasError: false }; |
| 15 | } |
| 16 | |
| 17 | static getDerivedStateFromError() { |
| 18 | // Update state so the next render will show the fallback UI. |
| 19 | return { hasError: true }; |
| 20 | } |
| 21 | |
| 22 | componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { |
| 23 | console.log(error, errorInfo); |
| 24 | } |
| 25 | |
| 26 | render() { |
| 27 | if (this.state.hasError) { |
| 28 | // You can render any custom fallback UI |
| 29 | return <h1>Something went wrong.</h1>; |
| 30 | } |
| 31 | |
| 32 | return this.props.children; |
| 33 | } |
| 34 | } |
nothing calls this directly
no outgoing calls
no test coverage detected