| 1 | import { Component, type ReactNode } from "react"; |
| 2 | import { reportCrash } from "../lib/crash"; |
| 3 | |
| 4 | export class ErrorBoundary extends Component<{ children: ReactNode }, { crashed: boolean }> { |
| 5 | state = { crashed: false }; |
| 6 | |
| 7 | static getDerivedStateFromError() { |
| 8 | return { crashed: true }; |
| 9 | } |
| 10 | |
| 11 | componentDidCatch(error: unknown, info: { componentStack?: string | null }) { |
| 12 | reportCrash("react", error, info.componentStack ?? undefined); |
| 13 | } |
| 14 | |
| 15 | render() { |
| 16 | return this.state.crashed ? null : this.props.children; |
| 17 | } |
| 18 | } |
| 19 |