I was reading the tutorial on the official react website. In the example about life cycle methods, under the componentDidMount method, a timerID is set to the setInterval fu
It's Simple. As soon as it React executes componentDidMount() life cycle method, the timer starts running.
this.timerID = setInterval( () => this.tick(), 1000 );
The above timer will run until the component gets unmounted (according to your code). It's not a surprise that your code works that way.