Browse Source

feat: add ErrorBoundary

develop
Ezerous 4 years ago
parent
commit
6247db7cbd
  1. 22
      packages/concordia-app/src/ErrorBoundary.jsx
  2. 5
      packages/concordia-app/src/index.jsx

22
packages/concordia-app/src/ErrorBoundary.jsx

@ -0,0 +1,22 @@
import React from 'react';
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError() {
return { hasError: true };
}
render() {
const { props: { children }, state: { hasError } } = this;
if (hasError) {
return <h1>Something went wrong.</h1>; // TODO: Make a better "Something went wrong" screen
}
return children;
}
}
export default ErrorBoundary;

5
packages/concordia-app/src/index.jsx

@ -3,15 +3,18 @@ import './utils/wdyr';
import React, { Suspense } from 'react'; import React, { Suspense } from 'react';
import { render } from 'react-dom'; import { render } from 'react-dom';
import App from './App'; import App from './App';
import ErrorBoundary from './ErrorBoundary';
import store from './redux/store'; import store from './redux/store';
import * as serviceWorker from './utils/serviceWorker'; import * as serviceWorker from './utils/serviceWorker';
import LoadingScreen from './components/LoadingScreen'; import LoadingScreen from './components/LoadingScreen';
import './assets/css/index.css'; import './assets/css/index.css';
render( render(
<ErrorBoundary>
<Suspense fallback={<LoadingScreen />}> <Suspense fallback={<LoadingScreen />}>
<App store={store} /> <App store={store} />
</Suspense>, </Suspense>
</ErrorBoundary>,
document.getElementById('root'), document.getElementById('root'),
); );

Loading…
Cancel
Save