From 6247db7cbd05afd94e95c5f4e227523219fff8a1 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Fri, 26 Feb 2021 17:19:14 +0200 Subject: [PATCH] feat: add ErrorBoundary --- packages/concordia-app/src/ErrorBoundary.jsx | 22 ++++++++++++++++++++ packages/concordia-app/src/index.jsx | 9 +++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 packages/concordia-app/src/ErrorBoundary.jsx diff --git a/packages/concordia-app/src/ErrorBoundary.jsx b/packages/concordia-app/src/ErrorBoundary.jsx new file mode 100644 index 0000000..86c97ef --- /dev/null +++ b/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

Something went wrong.

; // TODO: Make a better "Something went wrong" screen + } + return children; + } +} + +export default ErrorBoundary; diff --git a/packages/concordia-app/src/index.jsx b/packages/concordia-app/src/index.jsx index a29f530..1f4b575 100644 --- a/packages/concordia-app/src/index.jsx +++ b/packages/concordia-app/src/index.jsx @@ -3,15 +3,18 @@ import './utils/wdyr'; import React, { Suspense } from 'react'; import { render } from 'react-dom'; import App from './App'; +import ErrorBoundary from './ErrorBoundary'; import store from './redux/store'; import * as serviceWorker from './utils/serviceWorker'; import LoadingScreen from './components/LoadingScreen'; import './assets/css/index.css'; render( - }> - - , + + }> + + + , document.getElementById('root'), );