All that's left to do now is to update the state. React calls certain life cycle methods, which can be used to create side effects, such as timers or API requests. In our case, we will use two very commonly used React life cycle methods:
- componentDidMount(): This method is called when the component is rendered to the DOM for the first time. Note the difference to constructor(), which is called when the component is created. Creation happens much earlier than the actual rendering. componentDidMount offers a way to do something (creating timers, requests, and so on) when the component first appears.
- componentWillUnmount(): This method is called before the DOM produced by the component is removed. It is basically a ...