React Tutorial #17: Error Boundaries and Suspense
In the previous tutorial, you wrote tests for your React components. Now let’s make your app resilient with Error Boundaries and Suspense. What is an Error Boundary? When a component throws an error during rendering, React normally crashes the entire app. An Error Boundary catches the error and shows a fallback UI instead. Think of it like a try/catch block — but for React components. The Problem Without Error Boundaries function BrokenComponent() { throw new Error("Something went wrong!"); // Crashes the whole app return <div>This never renders</div>; } function App() { return ( <div> <Header /> <BrokenComponent /> {/* Crashes App */} <Footer /> </div> ); } Without an Error Boundary, the error propagates up and the whole page goes blank. ...