You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-3Lines changed: 6 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1165,7 +1165,7 @@
1165
1165
1166
1166
*Error boundaries* are 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.
1167
1167
1168
-
A class component becomes an error boundary if it defines a new lifecycle method called `componentDidCatch(error, info)`:
1168
+
A class component becomes an error boundary if it defines a new lifecycle method called `componentDidCatch(error, info)` or `staticgetDerivedStateFromError() `:
1169
1169
1170
1170
```jsx harmony
1171
1171
classErrorBoundaryextendsReact.Component {
@@ -1175,12 +1175,15 @@
1175
1175
}
1176
1176
1177
1177
componentDidCatch(error, info) {
1178
-
// Display fallback UI
1179
-
this.setState({ hasError:true })
1180
1178
// You can also log the error to an error reporting service
1181
1179
logErrorToMyService(error, info)
1182
1180
}
1183
1181
1182
+
staticgetDerivedStateFromError(error) {
1183
+
// Update state so the next render will show the fallback UI.
0 commit comments