ErrorBoundary: add error boundary to IconGrid

This commit is contained in:
Tobias Fried
2020-07-31 20:01:25 -04:00
parent f79eb5a5d3
commit d1f22a3dbc
3 changed files with 40 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
import React, { ErrorInfo } from "react";
interface ErrorBoundaryProps {
fallback?: JSX.Element;
}
export default class ErrorBoundary extends React.Component<ErrorBoundaryProps> {
state = { errorMessage: "" };
static getDerivedStateFromError(error: any) {
return { errorMessage: error.toString() };
}
componentDidCatch(error: any, info: ErrorInfo) {
console.error(error);
console.info(info);
}
render() {
if (this.state.errorMessage) {
return this.props.fallback ?? <p>{this.state.errorMessage}</p>;
}
return this.props.children;
}
}

View File

@@ -52,7 +52,7 @@
width: 100%;
height: 0px;
margin: 0px;
padding-right: 10%;
/* padding-right: 10%; */
border-radius: 16px;
overflow: hidden;
}
@@ -110,6 +110,16 @@
height: 48px;
}
.close {
width: 10%;
text-align: end;
}
.close-icon {
margin: 24px;
cursor: pointer;
}
.empty-list {
display: flex;
flex-direction: column;

View File

@@ -11,6 +11,7 @@ import { motion, AnimatePresence } from "framer-motion";
import { iconPreviewOpenAtom } from "../../state/atoms";
import { IconProps, Icon } from "phosphor-react";
import InfoPanel from "./InfoPanel";
import ErrorBoundary from "../ErrorBoundary/ErrorBoundary";
interface IconGridItemProps extends IconProps {
index: number;
@@ -100,7 +101,9 @@ const IconGridItem: React.FC<IconGridItemProps> = (props) => {
<p>{name}</p>
</motion.div>
<AnimatePresence initial={false}>
<ErrorBoundary fallback={<p>NOOOOOO</p>}>
{isOpen && <InfoPanel {...props} />}
</ErrorBoundary>
</AnimatePresence>
</>
);