From fd29f603676349c6a7f9e7431ef7218b870ee24a Mon Sep 17 00:00:00 2001 From: effozen Date: Tue, 3 Dec 2024 23:39:15 +0900 Subject: [PATCH] =?UTF-8?q?[FE][Fix]=20#376=20:=20=ED=9D=B0=EC=83=89=20?= =?UTF-8?q?=EB=B0=B0=EA=B2=BD=20=EC=95=88=EB=82=98=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EA=B1=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/routes/AlertUndefinedURL.tsx | 7 +--- frontend/src/utils/error/ErrorBoundary.tsx | 37 ---------------- .../src/utils/error/RouterErrorHandler.tsx | 42 ------------------- 3 files changed, 2 insertions(+), 84 deletions(-) delete mode 100644 frontend/src/utils/error/ErrorBoundary.tsx delete mode 100644 frontend/src/utils/error/RouterErrorHandler.tsx diff --git a/frontend/src/routes/AlertUndefinedURL.tsx b/frontend/src/routes/AlertUndefinedURL.tsx index d48ae07c..006f8db4 100644 --- a/frontend/src/routes/AlertUndefinedURL.tsx +++ b/frontend/src/routes/AlertUndefinedURL.tsx @@ -2,7 +2,7 @@ import { Navigate, useLocation } from 'react-router-dom'; import { useState } from 'react'; import { AlertUI } from '@/component/common/alert/Alert.tsx'; -export const AlertUndefinedURL = () => { +export const AlertUndefinedURL = ({ children }: { children?: JSX.Element }) => { const location = useLocation(); const [shouldRedirect, setShouldRedirect] = useState(false); const [showAlert, setShowAlert] = useState(true); @@ -24,10 +24,7 @@ export const AlertUndefinedURL = () => { }} /> )} -
-
잘못된 경로입니다.
-
메인 페이지로 이동합니다.
-
+ {children} ); }; diff --git a/frontend/src/utils/error/ErrorBoundary.tsx b/frontend/src/utils/error/ErrorBoundary.tsx deleted file mode 100644 index eda08470..00000000 --- a/frontend/src/utils/error/ErrorBoundary.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import React, { Component, ReactNode } from 'react'; - -interface IErrorBoundaryProps { - errorComponent: ReactNode; - children: ReactNode; -} - -interface IErrorBoundaryState { - hasError: boolean; - error: Error | null; -} - -export class ErrorBoundary extends Component { - constructor(props: IErrorBoundaryProps) { - super(props); - // eslint-disable-next-line react/no-unused-state - this.state = { hasError: false, error: null }; - } - - static getDerivedStateFromError(error: Error) { - return { hasError: true, error }; - } - - componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { - console.error(errorInfo); - - return { hasError: true, error }; - } - - render() { - if (this.state.hasError) { - return this.props.errorComponent; - } - - return this.props.children; - } -} diff --git a/frontend/src/utils/error/RouterErrorHandler.tsx b/frontend/src/utils/error/RouterErrorHandler.tsx deleted file mode 100644 index d1ed0d06..00000000 --- a/frontend/src/utils/error/RouterErrorHandler.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import { Navigate, useLocation } from 'react-router-dom'; -import { ReactNode, useState } from 'react'; -import { AlertUI } from '@/component/common/alert/Alert.tsx'; -import { ErrorBoundary } from '@/utils/error/ErrorBoundary.tsx'; - -interface IRouterErrorHandlerProps { - children: ReactNode; -} - -export const RouterErrorHandler = (props: IRouterErrorHandlerProps) => { - const location = useLocation(); - const [shouldRedirect, setShouldRedirect] = useState(false); - const [showAlert, setShowAlert] = useState(true); - - if (shouldRedirect) { - return ; - } - - const errorComponent = () => { - return ( - <> -
-
잘못된 경로입니다.
-
메인 페이지로 이동합니다.
-
- {showAlert && ( - { - setShowAlert(false); - setShouldRedirect(true); - }} - /> - )} - - ); - }; - - return {props.children}; -};