import React, { Component, ErrorInfo } from 'react' import { ErrorMessage } from './styled' interface IErrorBoundaryProps { children?: JSX.Element } interface IErrorBoundaryState { isError: boolean } export class ErrorBoundary extends Component< IErrorBoundaryProps, IErrorBoundaryState > { constructor(props: IErrorBoundaryProps) { super(props) this.state = { isError: false, } } public static getDerivedStateFromError(_: Error) { return { isError: true, } } render() { const { isError } = this.state const { children } = this.props if (isError) { return ( Something went wrong...
Try reloading the page or contact the administrator.
) } return children } } export default ErrorBoundary