Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/content/reference/react/Component.md
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,16 @@ We recommend defining components as functions instead of classes. [See how to mi

By default, if your application throws an error during rendering, React will remove its UI from the screen. To prevent this, you can wrap a part of your UI into an *Error Boundary*. An Error Boundary is a special component that lets you display some fallback UI instead of the part that crashed--for example, an error message.

<Note>
Error boundaries do not catch errors for:

- Event handlers [(learn more)](/learn/responding-to-events)
- Asynchronous code (e.g. `setTimeout` or `requestAnimationFrame` callbacks)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we caveat that with startTransition from useTransition in those scenarios behaving different? Erroring in a Transition that is bound to the Hook version will trigger Error boundaries.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback, I added the exception.

- [Server side rendering](/reference/react-dom/server)
- Errors thrown in the error boundary itself (rather than its children)

</Note>

To implement an Error Boundary component, you need to provide [`static getDerivedStateFromError`](#static-getderivedstatefromerror) which lets you update state in response to an error and display an error message to the user. You can also optionally implement [`componentDidCatch`](#componentdidcatch) to add some extra logic, for example, to log the error to an analytics service.

With [`captureOwnerStack`](/reference/react/captureOwnerStack) you can include the Owner Stack during development.
Expand Down