What is the need to unmount a component in React?


In the above mentioned example why do we need to unmount the timer. It works just fine without unmounting.

It’s good practice to end any asynchronous activity when you get rid of a component. If you unmount the component without clearing the timer, then the timer is still working in the background. This uses up resources, but more importantly it could affect data in unpredictable ways if the timer’s callback fires when you’re not expecting it to.