mirror of
https://github.com/re-rxjs/react-rxjs.git
synced 2025-12-08 18:01:51 +00:00
31 lines
521 B
TypeScript
31 lines
521 B
TypeScript
import { Component, ErrorInfo } from "react"
|
|
|
|
export class TestErrorBoundary extends Component<
|
|
{
|
|
onError: (error: Error, errorInfo: ErrorInfo) => void
|
|
},
|
|
{
|
|
hasError: boolean
|
|
}
|
|
> {
|
|
state = {
|
|
hasError: false,
|
|
}
|
|
|
|
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
this.props.onError(error, errorInfo)
|
|
}
|
|
|
|
static getDerivedStateFromError() {
|
|
return { hasError: true }
|
|
}
|
|
|
|
render() {
|
|
if (this.state.hasError) {
|
|
return "error"
|
|
}
|
|
|
|
return this.props.children
|
|
}
|
|
}
|