-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error boundaries to all hhd components
- Loading branch information
1 parent
005325b
commit 825afa4
Showing
3 changed files
with
150 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//@ts-nocheck | ||
import { Component } from "react"; | ||
import { Alert, AlertIcon } from "@chakra-ui/react"; | ||
|
||
type PropsType = { | ||
children: any; | ||
title?: string; | ||
}; | ||
type StateType = { | ||
hasError: boolean; | ||
title?: string; | ||
}; | ||
|
||
class ErrorBoundary extends Component<PropsType, StateType> { | ||
constructor(props) { | ||
super(props); | ||
this.state = { hasError: false, title: props?.title }; | ||
} | ||
|
||
static getDerivedStateFromError(error) { | ||
console.log(error); | ||
return { hasError: true }; | ||
} | ||
|
||
componentDidCatch(error, errorInfo) { | ||
console.log(error, errorInfo); | ||
} | ||
render() { | ||
if (this.state.hasError) { | ||
return ( | ||
<Alert status="error"> | ||
<AlertIcon /> | ||
Error while trying to render {this.props.title} | ||
</Alert> | ||
); | ||
} | ||
return this.props.children; | ||
} | ||
} | ||
|
||
export default ErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters