Browse Source

Merge pull request #136 from thomasyimgit/add-componentdidcatch-doc

Add `componentDidCatch()` document and link
main
Brian Vaughn 7 years ago
committed by GitHub
parent
commit
c702a51200
  1. 24
      content/docs/reference-react-component.md

24
content/docs/reference-react-component.md

@ -62,6 +62,12 @@ This method is called when a component is being removed from the DOM:
- [`componentWillUnmount()`](#componentwillunmount)
#### Error Handling
This method is called when there is an error during rendering, in a lifecycle method, or in the constructor of any child component.
- [`componentDidCatch()`](#componentdidcatch)
### Other APIs
Each component also provides some other APIs:
@ -250,6 +256,24 @@ componentWillUnmount()
* * *
### `componentDidCatch()`
```javascript
componentDidCatch(error, info)
```
Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed. Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
A class component becomes an error boundary if it defines this lifecycle method.
For more details, see [*Error Handling in React 16*](/blog/2017/07/26/error-handling-in-react-16.html).
> Note
>
> Error boundaries only catch errors in the components **below** them in the tree. An error boundary can’t catch an error within itself.
* * *
### `setState()`
```javascript

Loading…
Cancel
Save