unmounting

componentWillUnmount()

componentWillUnmount() is the only built-in method that gets called when a component is unmounted. The componentWillUnmount() method is invoked immediately before a component is unmounted and destroyed, removing the component from the DOM. This is used to clean up things left behind by a component. This is the ideal place to perform any cleanup, such as invalidating timers, cancelling network requests or cleaning up any subscriptions. Once a component instance is unmounted, it will never be mounted again.