In class components, lifecycle methods are special functions that React automatically calls at different phases of a component’s life.
Lifecycle Phases
| Phase | Explanation | Lifecycle methods |
|---|---|---|
| Mounting | The component is created and inserted into the DOM. | constructor(), render(), componentDidMount() |
| Updating | The component is re-rendered due to changes in props or state. | shouldComponentUpdate(), render(), componentDidUpdate() |
| Unmounting | The component is removed from the DOM. | componentWillUnmount() |
| Error Handling (React 16+) | Catching errors in child components. | componentDidCatch(), getDerivedStateFromError() |
Để lại một bình luận