What is updating?
The first time that a component instance renders, it does not update. A component updates every time that it renders, starting with the second render. There are five updating lifecycle methods:
- componentWillReceiveProps
- shouldComponentUpdate
- componentWillUpdate
- render
- componentDidUpdate
Whenever a component instance updates, it automatically calls all five of these methods, in order.
A component’s unmounting period occurs when the component is removed from the DOM. This could happen if the DOM is rerendered without the component, or if the user navigates to a different website or closes their web browser.
- componentWillUnmount is the only unmounting lifecycle method!
componentWillUnmount gets called right before a component is removed from the DOM. If a component initiates any methods that require cleanup, then componentWillUnmount is where putting that cleanup.