mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2026-01-15 12:15:02 +00:00
Fallback component for Error boundry
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
18
components/system/Apps/ComponentError.tsx
Normal file
18
components/system/Apps/ComponentError.tsx
Normal file
@@ -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 = () => (
|
||||
<StyledComponentError>{ERROR_MESSAGE}</StyledComponentError>
|
||||
);
|
||||
|
||||
export default ComponentError;
|
||||
@@ -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<RenderComponentProps> = ({
|
||||
id,
|
||||
}) => {
|
||||
const SafeComponent = (
|
||||
<ErrorBoundary>
|
||||
<ErrorBoundary FallbackRender={<ComponentError />}>
|
||||
<Component id={id} />
|
||||
</ErrorBoundary>
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@ const Index = (): React.ReactElement => {
|
||||
useLockTitle();
|
||||
|
||||
return (
|
||||
<ErrorBoundary reloadOnError>
|
||||
<ErrorBoundary>
|
||||
<Desktop>
|
||||
<Taskbar />
|
||||
<AppsLoader />
|
||||
|
||||
Reference in New Issue
Block a user