You can use the component ErrorBoundary
to display a fallback component when a Javascript error is caught in a children of the ErrorBoundary.
Reference documentation by React
The ErrorBoundary is wrapped by default around the main App
and renders the AppCrashFallback
for generic errors.
- Edit the
AppCrashFallback
to fit your design guidelines. - Send error to your monitoring system using the
componentDidCatch
from theErrorBoundary
.
You can define fallbacks at lower levels for custom error handling.
Ex: You display a graph rendered by a certain lib. If this lib does not work on some browsers you can display a fallback instead. Wrapp the graph in an ErrorBoundary
and choose the fallback to use instead by passing a FallbackComponent
prop.