Navigate to Tab Navigator from Stack Navigator with Params

I'm trying to navigate to a tab navigator stack with some key params that are needed for later API calls.

 navigation.dispatch(
        StackActions.replace('TABNAVIGATOR', {
          userName: username,
        }),
      );

This is the code that i have so far, but when i try to retrieve the info using:

const {userName} = route.params;

This returns this in console log:

 //console.log(route);
 {"key": "SOME_KEY", "name": "NAME_OF_COMPONENT", "params": undefined}

What am i doing wrong?

1 answer

  • answered 2020-11-20 11:44 anthony willis muñoz

    You should pass like this

     navigation.dispatch(
            StackActions.replace('TABNAVIGATOR', {
              params: {username: username},
            }),
          );
    
     navigation.dispatch(
            StackActions.replace('TABNAVIGATOR', {
              screen: 'TABNAVIGATORSCREEN1'
              params: {username: username},
            }),
          );