diff --git a/components/pages/ErrorBoundary.ts b/components/pages/ErrorBoundary.ts index 3bc8c153..37b65a9f 100644 --- a/components/pages/ErrorBoundary.ts +++ b/components/pages/ErrorBoundary.ts @@ -2,7 +2,7 @@ import type React from "react"; import { Component } from "react"; type ErrorBoundaryProps = { - reloadOnError?: boolean; + FallbackRender?: React.ReactNode; }; type ErrorBoundaryState = { @@ -28,15 +28,14 @@ export class ErrorBoundary extends Component< public render(): React.ReactNode { const { - props: { children, reloadOnError }, + props: { children, FallbackRender }, state: { hasError }, } = this; - if (hasError && reloadOnError) { + if (hasError && !FallbackRender) { window.location.reload(); } - // eslint-disable-next-line unicorn/no-null - return hasError ? null : children; + return hasError ? FallbackRender : children; } } diff --git a/components/system/Apps/ComponentError.tsx b/components/system/Apps/ComponentError.tsx new file mode 100644 index 00000000..1591406c --- /dev/null +++ b/components/system/Apps/ComponentError.tsx @@ -0,0 +1,18 @@ +import styled from "styled-components"; + +const StyledComponentError = styled.div` + display: flex; + font-size: 22px; + height: 100%; + place-content: center; + place-items: center; + width: 100%; +`; + +const ERROR_MESSAGE = "Error occured while loading component."; + +const ComponentError: FC = () => ( + {ERROR_MESSAGE} +); + +export default ComponentError; diff --git a/components/system/Apps/RenderComponent.tsx b/components/system/Apps/RenderComponent.tsx index 43ff26ea..7974c7b8 100644 --- a/components/system/Apps/RenderComponent.tsx +++ b/components/system/Apps/RenderComponent.tsx @@ -1,4 +1,5 @@ import { ErrorBoundary } from "components/pages/ErrorBoundary"; +import ComponentError from "components/system/Apps/ComponentError"; import dynamic from "next/dynamic"; const Window = dynamic(() => import("components/system/Window")); @@ -19,7 +20,7 @@ const RenderComponent: FC = ({ id, }) => { const SafeComponent = ( - + }> ); diff --git a/pages/index.tsx b/pages/index.tsx index 00a89904..64ccaf14 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -14,7 +14,7 @@ const Index = (): React.ReactElement => { useLockTitle(); return ( - +