Skip to content

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

Merged

Conversation

mathiassoeholm
Copy link
Contributor

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.

Copy link
Owner

@piotrwitek piotrwitek left a 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
Copy link
Owner

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:

Copy link
Contributor Author

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.

Copy link
Owner

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);
Copy link
Owner

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

Copy link
Contributor Author

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.

@piotrwitek
Copy link
Owner

LGTM, thanks @mathiassoeholm 👍

@piotrwitek piotrwitek merged commit f402ba6 into piotrwitek:master Apr 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants