0
Challenge · 39Hooks & Effects
Error Boundaries
Coreused in ~55% of apps
One component throws while rendering and React unmounts your whole app to a blank white screen. An Error Boundary catches that crash and shows a fallback instead — so a broken widget doesn't take down the entire page.
Core idea. An Error Boundary is a component that catches JavaScript errors thrown while rendering its subtree, displays a fallback UI instead of crashing the whole app, and lets you log the error and recover.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
the app on screen
<App/>
Navbar — still working
<ErrorBoundary>
<Profile/>
rendering normally
what happened
Trigger an error below. Only errors thrown during render are caught.
Render errors hit the boundary and swap in a fallback for just that subtree. Event-handler and async errors run outside rendering, so the boundary never sees them — those need try/catch.
↑ play a little first, then dig in