what does componentDidCatch do in react
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error) { // Update state so the next render will show the fallback UI. return { hasError: true }; }
componentDidCatch(error, errorInfo) { // You can also log the error to an error reporting service logErrorToMyService(error, errorInfo); }
render() {
if (this.state.hasError) { // You can render any custom fallback UI return <h1>Something went wrong.</h1>; }
return this.props.children;
}
}
Also in JavaScript:
- try catch with for loop in javascript
- javascript render jsx element x many times
- how to add a child to a parent element js
- remove extra space in string javascript
- react search bar
- html video tag autoplay not working
- append to array js
- Javascript generator example
- Add table row in jQuery
- how to flatten array with reduce in javascript
- click binding angular 8
- uuid react native expo
- how to sort by data in chart js
- flutter CircularProgressIndicator
- get ip adress express
- node js require file in parent directory
- js add element to array
- javascript listen for double click
- javascript round decimal 2 digits
- mongodb unwind
- const in javascript
- funciones invocan a funciones javascript
- object values javascript
- how to change a variables value in javascript