componentWillUnmount()
is invoked immediately before a component is unmounted and destroyed (removed from the DOM).
Perform any necessary cleanup in this method, such as invalidating timers, canceling network requests, like for example stopping setInterval()
timers before the component gets destroyed to prevent memory leaking .
You should not call setState() in the componentWillUnmount()
because the component will never be re-rendered. Once a component instance is unmounted, it will never be mounted again.