I'm using the Navigator in order to navigate between pages.
When Navigator.push() method is called, the "componentWillUnmount" method isn't called on the page we're navigating from.
It's a little bit problematic because I want to unsubscribe from listeners, etc.
Is it a normal behavior? When the "componentWillUnmount" is actually called?
This method is called during the unmounting phase of the React Lifecycle, i.e., before the component is destroyed or unmounted from the DOM tree. This method is majorly used to cancel all the subscriptions that were previously created in the componentWillMount method.
componentWillUnmount() is invoked immediately before a component is unmounted and destroyed. Perform any necessary cleanup in this method, such as invalidating timers, canceling network requests, or cleaning up any subscriptions that were created in componentDidMount() .
ReactJS componentWillUnmount() MethodThe componentWillUnmount() method allows us to execute the React code when the component gets destroyed or unmounted from the DOM (Document Object Model). This method is called during the Unmounting phase of the React Life-cycle i.e before the component gets unmounted.
The useEffect() hook is called when the component is mounted and sets the mounted. current value to true . The return function from the useEffect() hook is called when the component is unmounted and sets the mounted. current value to false .
Navigator
uses stack to manager route. When you push a new page, current page wont unmount, if you pop from new page to the current page, the new page will unmount.
And in other scene, if you render some child component based on some regulation like isLoading
or other, the componentWillUnmount
method will also be called when they no longer need to be rendered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With