]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/common/ErrorBoundary.js
4fbc562efd8a82a015a90f376693962b0062fa94
[alttp.git] / resources / js / components / common / ErrorBoundary.js
1 import PropTypes from 'prop-types';
2 import React from 'react';
3
4 class ErrorBoundary extends React.Component {
5         constructor(props) {
6                 super(props);
7                 this.state = {
8                         error: null,
9                 };
10         }
11
12         static getDerivedStateFromError(error) {
13                 return { error };
14         }
15
16         componentDidCatch(error, errorInfo) {
17                 console.log(error, errorInfo);
18         }
19
20         render() {
21                 const { children } = this.props;
22                 const { error } = this.state;
23                 if (error) {
24                         return <p>error</p>;
25                 }
26                 return children;
27         }
28 }
29
30 ErrorBoundary.propTypes = {
31         children: PropTypes.node,
32 };
33
34 export default ErrorBoundary;