In context of this exercise , I didn’t understand why we use “Mounting” instead of “Updating”.Can someone explain this?
It’s all about when the methods get called (and how often). If you had put the code they want you to insert into the
componentDidUpdate() method instead, then in this case, it would never get called because nothing else in the code causes an update. This means the time would never change.
Additionally, even if something else in the component did make a change that caused it to be called, the code provided uses
setInterval to update the state of the component with the new time every second, which only needs to be run once. Calling setInterval every time componentDidUpdate() is called would mean there are additional one second timers being created.
This is why the exercise asked you to insert the code into
componentDidMount(), which will definitely be called after the component is ready and will only be called once.