import React from "react";

class ErrorBoundary extends React.Component {
  constructor() {
    super();
    this.state = {
      hasErrored: false,
      error: null
    };
  }

  static getDerivedStateFromError(error) {
    //process the error
    console.log("error", error);
    return { hasErrored: true, error };
  }

  componentDidCatch(error, info) {
    console.log("error", error);
    console.log("info", info);
  }

  render() {
    if (this.state.hasErrored === true) {
      return <div>Uh oh, something went wrong.</div>;
    } else {
      return this.props.children;
    }
  }
}
export default ErrorBoundary;
