Replies: 2 comments
-
"use client";
import React from "react";
import { ErrorBoundary, useErrorBoundary } from "react-error-boundary";
function ErrorFallback({ error, resetErrorBoundary }) {
return (
<div role="alert">
<p>Something went wrong:</p>
<pre>{error.message}</pre>
<button onClick={resetErrorBoundary}>Try again</button>
</div>
);
}
function MyComponent() {
const { showBoundary } = useErrorBoundary();
const handleClick = () => {
try {
// Simulating an error
throw new Error("Oh no!");
} catch (error) {
showBoundary(error);
}
};
return <button onClick={handleClick}>Trigger Error</button>;
}
export default function Home() {
return (
<ErrorBoundary
FallbackComponent={ErrorFallback}
onReset={() => {
// Reset the state of your app here
}}
>
<MyComponent />
</ErrorBoundary>
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
@suprunchuk I mean not relying on this ‘react-error-boundary’ implementation. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
Currently can only handle expected errors and uncaught exceptions,
For other errors, I can only handle them in the following way:
Is there a more elegant way like:
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions