MERN STACK TUTORIAL
import React, { component } from 'react';
class ErrorBoundary extends Component {
state = {
hasError: false,
errorMessage: ''
}
componentDidCatch = (error, info) => {
this.setState({hasError: true, errorMessage: error});
}
render() {
if (this.state.hasError) {
return <h1>{this.state.errorMessage}</h1>;
} else {
return this.props.children;
}
}
}
export default ErrorBoundary;
-
- constructor(props)
-
- getDerivedStateFromProps(props, state)
-
- getSnapshotBeforeUpdate(prevProps, prevState)
-
- componentDidCatch()
-
- componentWillUnmount()
-
- shouldComponentUpdate(nextProps, nextState)
-
- componentDidUpdate()
-
- componentDidMount()
-
- render()
1 --> 2 --> 9 --> 8
Component Lifecycle - Update 2 --> 6 --> 9 --> 3 --> 7