What is the need to unmount a component in React?

What is the need to unmount a component in React?
0

#1

https://jsfiddle.net/dannymarkov/aLhp9jvg/1/?utm_source=website&utm_medium=embed&utm_campaign=aLhp9jvg

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


#2

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.