ReactAdvanced#errors

What is an error boundary?

A class component implementing componentDidCatch/getDerivedStateFromError that catches render-time errors in its subtree and shows a fallback UI instead of a blank page. It does not catch event handler or async errors.

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

Related Questions

1
ReactIntermediate#lifecycle#hooks

How does the component lifecycle map to hooks?

Open
2
ReactAdvanced#performance

What is lazy loading and code splitting in React?

Open
3
ReactAdvanced#performance#data

What is Suspense?

Open