Files
commafeed/commafeed-client/src/components/ErrorBoundary.tsx

27 lines
630 B
TypeScript
Raw Normal View History

2022-08-14 21:05:22 +02:00
import { ErrorPage } from "pages/ErrorPage"
2023-12-28 19:54:51 +01:00
import React, { type ReactNode } from "react"
2022-08-14 21:05:22 +02:00
interface ErrorBoundaryProps {
children?: ReactNode
}
interface ErrorBoundaryState {
error?: Error
}
export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
constructor(props: ErrorBoundaryProps) {
super(props)
this.state = {}
}
componentDidCatch(error: Error) {
this.setState({ error })
}
render() {
if (this.state.error) return <ErrorPage error={this.state.error} />
return this.props.children
}
}