ErrorBoundary....reload app

This commit is contained in:
yonghyon
2024-08-06 12:53:17 +09:00
parent 68c9f35b31
commit a6ad290ae1
2 changed files with 40 additions and 8 deletions

View File

@@ -41,6 +41,7 @@ import { $L, clearLaunchParams, getLaunchParams } from "../utils/helperMethods";
import MainView from "../views/MainView/MainView";
import css from "./App.module.less";
import { getMenuByLinkTpCd, handleDeepLink } from "./deepLinkHandler";
import ErrorBoundary from "../views/ErrorBoundary";
let foreGroundChangeTimer = null;
@@ -302,14 +303,9 @@ function AppBase(props) {
}, [dispatch]);
return (
<MainView
className={
typeof window === "object" &&
!window.PalmSystem &&
!cursorVisible &&
css.preventMouse
}
/>
<ErrorBoundary>
<MainView className={typeof window === "object" && !window.PalmSystem && !cursorVisible && css.preventMouse} />
</ErrorBoundary>
);
}

View File

@@ -0,0 +1,36 @@
import React, { Component } from "react";
import { connect } from "react-redux";
import { clearLaunchParams } from "../utils/helperMethods";
class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error) {
return { hasError: true };
}
componentDidCatch(error, errorInfo) {
console.error("Uncaught error:", error, errorInfo);
}
componentDidUpdate(prevProps, prevState) {
if (this.state.hasError) {
clearLaunchParams();
if (typeof window === "object") {
window.location.reload();
}
}
}
render() {
if (this.state.hasError) {
return <div>Something went wrong.</div>;
}
return this.props.children;
}
}
export default connect()(ErrorBoundary);