Skip to content
Learn Netverks

Lesson

Step 33/36 92% through track

error-boundaries

Error boundaries

Last reviewed May 28, 2026 Content v20260528
Track mode
client_react
Means
In-browser React TSX
Reading
~1 min
Level
advanced

This lesson

This lesson teaches Error boundaries: the concepts, APIs, and habits you need before advancing in React.

Without Error boundaries, you will struggle to read or extend React codebases and playground exercises.

You will apply Error boundaries in contexts like: SPAs, dashboards, design-system-driven products, and React Native mobile apps.

Write TypeScript/TSX, click Run in browser—React 18 loads from CDN, JSX compiles in the tab, UI renders in the preview root, and printOutput feeds the terminal.

When hooks, state, and effects from intermediate lessons are familiar.

JavaScript errors during render can unmount the entire tree. An error boundary is a class component (or future API) that catches errors in child render/lifecycle methods and shows fallback UI instead of a blank screen.

What boundaries catch

  • Errors in child render
  • Errors in lifecycle methods of descendants

What they do NOT catch

  • Event handler errors (wrap try/catch inside handlers)
  • Async errors unless rethrown into render
  • Errors in the boundary itself

Pattern

class Boundary extends React.Component {
  state = { hasError: false };
  static getDerivedStateFromError() { return { hasError: true }; }
  render() {
    return this.state.hasError ? <p>Something went wrong</p> : this.props.children;
  }
}

In production apps, log errors to monitoring (Sentry, etc.) inside componentDidCatch. This playground focuses on the concept—most function components rely on route-level boundaries higher in the tree.

Self-check

  1. Where should you handle fetch failures vs render throws?
  2. Why are error boundaries still class-based in React 18?

Tip: Wrap route-level sections, not every button—granular boundaries isolate failures without hiding all UI.

Interview prep

What do error boundaries catch?

Render errors in descendants so you can show fallback UI. They do not catch event-handler or async errors unless rethrown into render.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • What errors caught?
  • What not caught?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump