Add error boundary

pull/225/head
Uku Taht 6 years ago
parent 4d55c4657a
commit 9ccd7c9598

@ -0,0 +1,26 @@
import React from 'react';
import RocketIcon from './stats/modals/rocket-icon'
export default class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = {error: null}
}
static getDerivedStateFromError(error) {
return {error: error}
}
render() {
if (this.state.error) {
return (
<div className="text-center text-gray-900 mt-36">
<RocketIcon />
<div className="text-lg font-bold">Oops! Something went wrong</div>
<div className="text-lg">{this.state.error.name + ': ' + this.state.error.message}</div>
</div>
)
}
return this.props.children;
}
}

@ -3,6 +3,7 @@ import ReactDOM from 'react-dom';
import 'url-search-params-polyfill';
import Router from './router'
import ErrorBoundary from './error-boundary'
const container = document.getElementById('stats-react-container')
@ -13,5 +14,11 @@ if (container) {
hasGoals: container.dataset.hasGoals === 'true'
}
ReactDOM.render(<Router site={site} />, container);
const app = (
<ErrorBoundary>
<Router site={site} />
</ErrorBoundary>
)
ReactDOM.render(app, container);
}

Loading…
Cancel
Save