Skip to content
Justice Tech School

Error Boundaries

A class with getDerivedStateFromError catches render errors below it.

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

Exercise

Catch render errors.

Error  catch render errors

Quiz Test

What do error boundaries catch?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.