-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
882a848
commit 29db49d
Showing
9 changed files
with
177 additions
and
68 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { ReactNode, useState, useCallback } from 'react'; | ||
import { ErrorBoundary as ReactErrorBoundary } from 'react-error-boundary'; | ||
|
||
interface ErrorBoundaryProps { | ||
children: ReactNode; | ||
} | ||
|
||
function ErrorFallback({ error, resetErrorBoundary }: { error: Error; resetErrorBoundary: () => void }) { | ||
return ( | ||
<div role="alert"> | ||
<p>Something went wrong:</p> | ||
<pre>{error.message}</pre> | ||
<button onClick={resetErrorBoundary}>Try again</button> | ||
</div> | ||
); | ||
} | ||
|
||
export function ErrorBoundary({ children }: ErrorBoundaryProps) { | ||
const [errorInfo, setErrorInfo] = useState<React.ErrorInfo | null>(null); | ||
|
||
const handleError = useCallback((error: Error, info: React.ErrorInfo) => { | ||
console.error("Uncaught error:", error, info); | ||
setErrorInfo(info); | ||
}, []); | ||
|
||
return ( | ||
<ReactErrorBoundary | ||
FallbackComponent={ErrorFallback} | ||
onError={handleError} | ||
onReset={() => setErrorInfo(null)} | ||
> | ||
{children} | ||
</ReactErrorBoundary> | ||
); | ||
} | ||
|
||
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
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
Oops, something went wrong.