mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
27 lines
630 B
TypeScript
27 lines
630 B
TypeScript
import { ErrorPage } from "pages/ErrorPage"
|
|
import React, { type ReactNode } from "react"
|
|
|
|
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
|
|
}
|
|
}
|