mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 12:13:11 +00:00
Add note on error boundary limitations (#8108)
This commit is contained in:
@@ -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)
|
||||
- [Server side rendering](/reference/react-dom/server)
|
||||
- Errors thrown in the error boundary itself (rather than its children)
|
||||
- Asynchronous code (e.g. `setTimeout` or `requestAnimationFrame` callbacks); an exception is the usage of the [`startTransition`](/reference/react/useTransition#starttransition) function returned by the [`useTransition`](/reference/react/useTransition) Hook. Errors thrown inside the transition function are caught by error boundaries [(learn more)](/reference/react/useTransition#displaying-an-error-to-users-with-error-boundary)
|
||||
|
||||
</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.
|
||||
|
||||
Reference in New Issue
Block a user