Search code examples
react-nativewix-react-native-navigation

Why React native navigation loads all components at the same time?


I am using react native navigation v2 by wix. I have a welcome screen with login screen and register. I start the startAuth.js from App.js. There are two tabs with login and register.

Welcome screen

But as soon as app starts the componentWillMount methods runs in the register screen but yet i am at login tab.

Welcome Tabs

Why is this happening?


Solution

  • react-native-navigation's Tab does not support lazy loading. But there are two special lifecyle functions where you can put your logic when component appear or disappear on screen

    • componentDidAppear(): called each time this component appears on screen
    • componentDidDisappear(): called each time this component disappears from screen

    https://wix.github.io/react-native-navigation/docs/screen-lifecycle

    There is also a discussion about topic https://github.com/wix/react-native-navigation/issues/1250