diff --git a/src/shared/utils/ErrorBoundary/ErrorComponent.tsx b/src/shared/utils/ErrorBoundary/ErrorComponent.tsx index b09b7f8..a9d2ab1 100644 --- a/src/shared/utils/ErrorBoundary/ErrorComponent.tsx +++ b/src/shared/utils/ErrorBoundary/ErrorComponent.tsx @@ -1,9 +1,25 @@ -import { FC } from 'react'; +import { FC, useEffect, useRef } from 'react'; +import { FallbackProps } from 'react-error-boundary'; +import { useLocation } from 'react-router-dom'; -export const ErrorComponent: FC<{ error: any }> = ({ error }) => ( -
-

Error

-

Something bad happened

-
{error.message}
-
-); +export const ErrorComponent: FC = ({ + error, + resetErrorBoundary +}) => { + const location = useLocation(); + const initialPathname = useRef(location.pathname); + + useEffect(() => { + if (location.pathname !== initialPathname.current) { + resetErrorBoundary(); + } + }, [initialPathname, location.pathname, resetErrorBoundary]); + + return ( +
+

Error

+

Something bad happened

+
{error.message}
+
+ ); +};