-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Error boundary example fix #166
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
Error boundary example fix #166
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, please check my comments. Thanks!
<button | ||
type="button" | ||
onClick={() => { | ||
// We don't just throw the error here, because error boundaries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer just:
Error boundaries catch errors during rendering and do not work inside event handlers:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh, I think that comment will just confuse whoever is reading through the example. I removed the comment altogether now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's fine 👍
</button > | ||
); | ||
const BrokenButton = () => { | ||
const [throwError, setThrowError] = useState(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename throwError
to shouldRenderBrokenComponent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line became quite long because of [shouldRenderBrokenComponent, setShouldRenderBrokenComponent]
so I think setShouldBreak
would be a better name.
LGTM, thanks @mathiassoeholm 👍 |
This PR fixes the error boundary example.
I've added a comment explaining why we can't just throw the error from the event handler.
I hope the example is not too complex now. We can remove the comment, if you think it's too distracting?
I think it's better than having an example that doesn't work though. I ended up spending quite a bit of time figuring out why my error boundary wouldn't work, because of it.