← React Intermediate Questions - Set 10 Q93

How can you implement error boundaries in React?

React Intermediate Questions - Set 10

Example

class Boundary extends Component {
  state = { error: null };
  static getDerivedStateFromError(error) { return { error }; }
  render() { return this.state.error ? <Fallback /> : this.props.children; }
}

What to notice

← Back to the question list