Use static getDerivedStateFromError(error) to switch the interface to fallback UI, and componentDidCatch(error, info) to report the failure. The second method receives info.componentStack, which identifies the failing component and its ancestors. Send the error and stack to your backend or monitoring service without making the reporting request part of the fallback-rendering path.
Use the boundary’s reporting lifecycle method
React separates the boundary’s UI response from its side effects: getDerivedStateFromError updates state so the boundary can render a fallback, while componentDidCatch is where React documents logging to an error-reporting service. The React Component reference describes info.componentStack as the trace of the component tree where the error occurred.
class ErrorBoundary extends React.Component {
state = { hasError: false };
static getDerivedStateFromError(error) {
return { hasError: true };
}
componentDidCatch(error, info) {
reportError({
error,
componentStack: info.componentStack,
});
}
render() {
return this.state.hasError ? this.props.fallback : this.props.children;
}
}
This is an illustrative pattern; adapt the reporting function and payload to your application. Keep the state update synchronous and focused on fallback rendering. Treat reporting as a separate side effect, so a failed request does not block the fallback from appearing.
Build a useful, safe report payload
At minimum, include the thrown value and component stack. If your application already tracks deployment context, you may also include fields such as release and environment to help correlate a report with a build. There is no universally safe payload or retention policy established here: choose fields and handling rules that fit your backend and data practices.
#1 Best Overall
- Normalize unknown thrown values. JavaScript permits throwing values such as strings or
null, not justErrorobjects. Avoid assumingerror.messageexists; convert values into a serializable representation before sending them. - Preserve the component stack. Forward
info.componentStackas a separate field so it is not confused with a JavaScript stack trace. - Handle transport failures independently. A network outage or rejected reporting request should not replace or prevent the boundary’s fallback UI.
Make production component stacks readable
React notes that component names are minified in production. Source maps can decode the component stack in the same way they decode ordinary JavaScript error stacks. Make the relevant maps available to your backend or monitoring service’s symbolication workflow. The right upload and access arrangement depends on your build and service setup; avoid exposing source maps publicly by accident.
Know what Error Boundaries do not catch
An Error Boundary is not a global exception handler. React’s reference excludes failures in event handlers, server-side rendering, the boundary itself, and most asynchronous callbacks. Those paths need their own error handling and reporting. React identifies errors thrown inside the transition function passed to startTransition from useTransition as an exception to the general asynchronous limitation. See the React documentation for the current behavior.
Choose where reports go
A custom endpoint gives your team direct control over ingestion and storage, while a hosted monitoring service may provide an existing workflow for grouping and triaging issues. Consider who owns storage and access, the setup and maintenance involved, source-map handling, data controls, and alerting needs. Those are decision criteria, not a universal ranking of services.
Sentry is one example of a service with a React SDK. Its React guide describes its React integration, including an ErrorBoundary. For React 19, the guide also discusses onCaughtError and onUncaughtError; consult the current SDK documentation before using vendor-specific setup.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsRank #3
Function-component boundaries
React’s current reference says there is no direct componentDidCatch equivalent for function components and that Error Boundaries cannot currently be written as function components. Use a reusable class boundary or a package such as react-error-boundary when you want to consume boundary behavior from a function-component application.
Quick Recap
Best Value
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




