Path: blob/1.0-develop/resources/scripts/components/elements/ErrorBoundary.tsx
7461 views
import React from 'react';1import tw from 'twin.macro';2import Icon from '@/components/elements/Icon';3import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';45interface State {6hasError: boolean;7}89// eslint-disable-next-line @typescript-eslint/ban-types10class ErrorBoundary extends React.Component<{}, State> {11state: State = {12hasError: false,13};1415static getDerivedStateFromError() {16return { hasError: true };17}1819componentDidCatch(error: Error) {20console.error(error);21}2223render() {24return this.state.hasError ? (25<div css={tw`flex items-center justify-center w-full my-4`}>26<div css={tw`flex items-center bg-neutral-900 rounded p-3 text-red-500`}>27<Icon icon={faExclamationTriangle} css={tw`h-4 w-auto mr-2`} />28<p css={tw`text-sm text-neutral-100`}>29An error was encountered by the application while rendering this view. Try refreshing the page.30</p>31</div>32</div>33) : (34this.props.children35);36}37}3839export default ErrorBoundary;404142