2

How we can remove listeners in React-native-navigation on app kill . Because in the starting of the app there is no root component but just a class there is no componentWillUnMount. I need to remove some listeners on app kill for example react-native-fcm listeners and socket client listeners. Thanks

2 Answers2

0

You can unregister listeners when the root component is unmounted.

For example; in this root layout, you can do clean up when navigation.playground.WelcomeScreen unmounts.

Navigation.setRoot({
  root: {
    stack: {
      id: 'TEST',
      children: [
        {
          component: {
            name: 'navigation.playground.WelcomeScreen'
          }
        }
      ]
    }
  }
});
guy.gc
  • 3,359
  • 2
  • 24
  • 39
0

The root component stack unmount as we move to another stack by using Navigation.setRoot there is no parent root here in this navigation where we can register or unregister the listeners.