import React from 'react' type State = { error?: Error } type Props = { children: React.ReactNode } export class ErrorBoundary extends React.Component { constructor(props: Props) { super(props) this.state = {} } static getDerivedStateFromError(error: Error) { return { error } } componentDidCatch(error: Error, errorInfo: unknown) { console.error(error, errorInfo) } render() { if (this.state.error) { return (
Something went wrong rendering this component: {this.state.error.message}
) } return this.props.children } }