skip to Main Content

In react native, even though App is the initial entry point but Home screen is called first. Is it because Home is the initialRouteName defined in the NavigationContainer. If so, then how to initiate Home screen only after App component completes its operation in useEffect method.

function App(): JSX.Element {      
    useEffect(() => {
    console.log("App");
  }, []);
  return (
    <AppNavigation></AppNavigation>
  );
}

const AppNavigation = () => {
return (
     <NavigationContainer>
       <Stack.Navigator       >
<Drawer.Navigator
        initialRouteName="home"
      >...
      </Drawer.Navigator>         
     </NavigationContainer>
  );
};

2

Answers


  1. Solution:

    Please check the index.js file:

    AppRegistry.registerComponent(appName, () => App)  // Here App is the entry point
    

    In your case:
    The entry point may changed to home:

    AppRegistry.registerComponent(appName, () => home) 
    
    Login or Signup to reply.
  2. Solution:

    You can try by adding the modified module & line:

    function App(): JSX.Element {      
        useEffect(() => {
        console.log("App");
      }, []);
      return (
        <AppNavigation />      //modified line
      );
    }
    
    
    //modified module
    
    const AppNavigation = () => {
    return (
         <NavigationContainer>
           <Drawer.Navigator initialRouteName="home">
            <Drawer.Screen name="Home" component={Home} />    //your component
          </Drawer.Navigator>       
         </NavigationContainer>
      );
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search