Skip to main content
InterviewHubPRO
Section Overview
Q173

Question 173 of 407

Part 8: Advanced React Patterns, Portals & Performance (152 - 261)

43%
React Core & Hooks (407 Qs)•Part 8: Advanced React Patterns, Portals & Performance (152 - 261)

What is the behavior of uncaught errors in react 16?

junior LevelCode ExampleFormsPerformance

Note: This behavior was introduced in React 16 and continues in React 18/19.

In React 16+, errors that are not caught by any error boundary will result in unmounting of the whole React component tree. The reason behind this decision is that it is worse to leave corrupted UI in place than to completely remove it. For example, it is worse for a payments app to display a wrong amount than to render nothing.

Best Practice: Always wrap your application or critical sections in error boundaries to prevent complete unmounting and provide a better user experience.

jsx
<ErrorBoundary fallback={<ErrorPage />}>
<App />
</ErrorBoundary>