-
-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-render ErrorFallback from onError handler output #79
Comments
Hi @maurocarrero thanks for reaching us 😄 . A possible not really clean way is to do as below, using two import * as React from "react";
import { ErrorBoundary as ReactErrorBoundary } from "react-error-boundary";
function ErrorComponent({ error }) {
return <div>Error {error.timestamp}</div>;
}
class ErrorWithTimestamp extends Error{
constructor(message,timestamp){
super(message)
this.timestamp = timestamp
}
}
function ErrorBoundary({ children }) {
const throwErrorWithTimestamp = (error) => {
throw new ErrorWithTimestamp(error.message, new Date().getTime())
};
const handleError = (error) => {
console.log(error.timestamp);
};
return (
<ReactErrorBoundary
FallbackComponent={ErrorComponent}
onError={handleError}
>
<ReactErrorBoundary FallbackComponent={ErrorComponent} onError={throwErrorWithTimestamp}>
{children}
</ReactErrorBoundary>
</ReactErrorBoundary>
);
}
export default ErrorBoundary; |
Hi @marcosvega91, useful and clean solution. |
Happy that is working for you |
react-error-boundary
version: 3.0.2node
version: 12.19.0npm
version: 6.14.8This is not a failure but instead a question about a possible use case.
Is there a way to do this with current implementation?
Suggested solution:
Something like:
Thanks!
The text was updated successfully, but these errors were encountered: