JavaScript React Components Stateful Components and Lifecycle Methods Update the Stopwatch State with componentDidMount()

setInterval() inside componentDidMount()

Why you would run a timer function inside componentDidMount()? This way, the function is constantly running in the background, even if start wasn't clicked. Wouldn't that be a bad practice for larger application? Or is it just being used here to show us how componentDidMount() works?

Jeremy Antoine
Jeremy Antoine
14,713 Points

I do believe that he was showing us two things. First, how componentDidMount() begins as soon as the page loads. Second, how it shows, as the start button is pushed, that it starts from 0 again.