From 8b17d67bdf366a10d0f152e3a4c0c87020513d40 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 15 Sep 2022 10:29:35 -0700 Subject: Add react error handler --- modern/src/ErrorBoundary.js | 39 +++++++++++++++++++++++++++++++++++++++ modern/src/index.js | 35 +++++++++++++++++++---------------- 2 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 modern/src/ErrorBoundary.js (limited to 'modern') diff --git a/modern/src/ErrorBoundary.js b/modern/src/ErrorBoundary.js new file mode 100644 index 00000000..5a24435f --- /dev/null +++ b/modern/src/ErrorBoundary.js @@ -0,0 +1,39 @@ +import React from 'react'; +import { Alert } from '@mui/material'; + +class ErrorBoundary extends React.Component { + constructor(props) { + super(props); + this.state = { + error: null, + }; + } + + static getDerivedStateFromError(error) { + return { error }; + } + + componentDidCatch(error, errorInfo) { + console.log(error); + console.log(errorInfo); + } + + render() { + const { error } = this.state; + if (error) { + return ( + + ').replaceAll(' ', ' '), + }} + /> + + ); + } + const { children } = this.props; + return children; + } +} + +export default ErrorBoundary; diff --git a/modern/src/index.js b/modern/src/index.js index d89d917e..e5457789 100644 --- a/modern/src/index.js +++ b/modern/src/index.js @@ -13,27 +13,30 @@ import preloadImages from './map/core/preloadImages'; import * as serviceWorkerRegistration from './serviceWorkerRegistration'; import NativeInterface from './common/components/NativeInterface'; import ServerProvider from './ServerProvider'; +import ErrorBoundary from './ErrorBoundary'; preloadImages(); const root = createRoot(document.getElementById('root')); root.render( - - - - - - - - - - - - - - - - , + + + + + + + + + + + + + + + + + + , ); serviceWorkerRegistration.register(); -- cgit v1.2.3