0

On React 16, let's say I have a component like

class Profile extends React.Component {
  onClick = () => {
      throw new Error("Oh nooo!");
    });
  };

  componentDidCatch(error, info) {
     alert(error)
  }
  render() {
    return (
      <div onClick={this.onClick}>
        Name: {this.props.user.name}
      </div>
  );
}

}

and then in the constructor I do this.onClick = this.onClick.bind(this). Will the error be catched in componentDidCatch() ?

1 Answers1

1

Now, it only catches errors in the components below them in the tree.

See: Error Handling in React 16

mxmtsk
  • 4,285
  • 6
  • 22
  • 47