mirror of
https://github.com/vernu/textbee.git
synced 2026-02-20 07:34:00 -05:00
35 lines
655 B
TypeScript
35 lines
655 B
TypeScript
import React, { Component } from 'react'
|
|
|
|
interface ErrorBoundaryProps {
|
|
fallback?: string | React.ReactNode
|
|
children: React.ReactNode
|
|
}
|
|
|
|
interface ErrorBoundaryState {
|
|
hasError: boolean
|
|
}
|
|
|
|
export default class ErrorBoundary extends Component<
|
|
ErrorBoundaryProps,
|
|
ErrorBoundaryState
|
|
> {
|
|
state = { hasError: false }
|
|
|
|
static getDerivedStateFromError(error) {
|
|
console.log(error)
|
|
return { hasError: true }
|
|
}
|
|
|
|
componentDidCatch(error, errorInfo) {
|
|
console.log(error, errorInfo)
|
|
}
|
|
|
|
render() {
|
|
if (this.state.hasError) {
|
|
return this.props.fallback || 'Something went wrong'
|
|
}
|
|
|
|
return this.props.children
|
|
}
|
|
}
|