14

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?

Rom Shiri
  • 1,390
  • 4
  • 16
  • 29
  • It's not an anwer, but your question has been addressed a long time ago on GitHub, maybe you'll find an answer in this direction: https://github.com/facebook/react-native/issues/1025 – Thanh-Quy Nguyen Jun 05 '16 at 22:49

2 Answers2

15

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.

Teivaz
  • 5,462
  • 4
  • 37
  • 75
liu pluto
  • 314
  • 2
  • 11
1

In react-native, componentWillUnmount is not called as you would expect on the web. Instead try to use the navigation lifecycle, in whatever navigation library you are using (we are using react-navigation).

JackDev
  • 4,891
  • 1
  • 39
  • 48