-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created ErrorBoundary class component and implmented into _app.tsx
- Loading branch information
Showing
4 changed files
with
65 additions
and
36 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 |
---|---|---|
@@ -1,22 +1,42 @@ | ||
// import { ErrorBoundary as ReactErrorBoundary } from "react-error-boundary"; | ||
import React, { PropsWithChildren } from "react"; | ||
// import { logger } from "../../utils"; | ||
// import { ClientSideError } from "./ClientSideError"; | ||
|
||
// const clientSideErrorHandler = ( | ||
// error: Error, | ||
// { componentStack }: { componentStack: string } | ||
// ) => { | ||
// logger.error(error.message, componentStack); | ||
// }; | ||
|
||
export const ErrorBoundary: React.FC<PropsWithChildren> = ({ children }) => { | ||
return ( | ||
// <ReactErrorBoundary | ||
// FallbackComponent={ClientSideError} | ||
// onError={clientSideErrorHandler} | ||
// > | ||
<div>{children}</div> | ||
// </ReactErrorBoundary> | ||
); | ||
}; | ||
import React, { Component, ErrorInfo } from 'react'; | ||
|
||
interface IProps { | ||
fallback: React.FC; | ||
children: React.ReactNode; | ||
} | ||
|
||
interface IState { | ||
hasError: boolean; | ||
} | ||
|
||
export class ErrorBoundary extends Component<IProps, IState>{ | ||
|
||
state = {hasError: false}; | ||
|
||
constructor(props: IProps) { | ||
super(props); | ||
this.state = {hasError: false}; | ||
} | ||
|
||
static getDerivedStateFromError(error: Error) { | ||
// Update state so the next render will show the fallback UI. | ||
console.error(error); | ||
console.error("error boundary reached"); | ||
return { hasError: true }; | ||
} | ||
|
||
componentDidCatch(error: Error, errorInfo: ErrorInfo) { | ||
// You can also log the error to an error reporting service | ||
console.error(error, errorInfo); | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
return (<> | ||
{this.props.fallback} | ||
</>) | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} |
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
Empty file.
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