← React Beginner Questions - Set 12 Q116

How do you handle errors in React?

React Beginner Questions - Set 12

Example

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

What to notice

← Back to the question list