From d3c7705bedebd65c94f9eea691aaf2fe03b0cafe Mon Sep 17 00:00:00 2001
From: Anton Tananaev <anton@traccar.org>
Date: Sat, 19 Aug 2023 13:58:45 -0700
Subject: Move to Vite

---
 modern/src/ErrorBoundary.jsx | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 modern/src/ErrorBoundary.jsx

(limited to 'modern/src/ErrorBoundary.jsx')

diff --git a/modern/src/ErrorBoundary.jsx b/modern/src/ErrorBoundary.jsx
new file mode 100644
index 00000000..93a6fe0f
--- /dev/null
+++ b/modern/src/ErrorBoundary.jsx
@@ -0,0 +1,35 @@
+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 };
+  }
+
+  /* eslint-disable react/no-danger */
+  render() {
+    const { error } = this.state;
+    if (error) {
+      return (
+        <Alert severity="error">
+          <code
+            dangerouslySetInnerHTML={{
+              __html: error.stack.replaceAll('\n', '<br>').replaceAll(' ', '&nbsp;'),
+            }}
+          />
+        </Alert>
+      );
+    }
+    const { children } = this.props;
+    return children;
+  }
+}
+
+export default ErrorBoundary;
-- 
cgit v1.2.3

