import * as React from 'react';

interface Props {}
class ErrorBoundary extends React.Component<Props> {
  state = { hasError: false };

  constructor(props: Props) {
    super(props);
  }

  static getDerivedStateFromError(error: Error) {
    return { hasError: true };
  }

  componentDidCatch(error: Error, errorInfo: any) {
    console.log('error', error, 'errorInfo', errorInfo);
  }

  render() {
    if (this.state.hasError) {
      return <div>出错啦, 请查看控制台</div>;
    } else {
      return this.props.children;
    }
  }
}

export default ErrorBoundary;
