0

Hi is that possible to pass certain parameter when pressing the TabBar?

Currently I have an administrator who could view lists of data in ProfileScreenPrimary, and then when he click the list he will go to profilescreen secondary that show details of the data from parameter

it works fine

and then i made a route for customer that will skip the profilescreenprimary and will go to profilescreensecondary. but it got error which is the route.params is undefined, is there any way to pass the parameter / replace the parameters with context that i provide?

, i have tabBar like this tabBar

function BottomTabNavigator() {
  return (
    <Tab.Navigator>
      <Tab.Screen
        name="Profile"
        component={ProfileStackScreen}
        options={{
          tabBarLabel: 'PROFILE',
          tabBarIcon: ({color, size}) => (
            <Icon name="git-branch" color={color} size={25} />
          ),
        }}
      />
      <another tab....>
    </Tab.Navigator>
  );
}

this is my profileStackScreen


function ProfileStackScreen({navigation, route}) {
  const {myContext}=useContext(MYCONTEXT)
  return (  
{
   myContext.role = 'admin' && (
       <Stack.Screen
        name="ProfileScreenPrimary"
        component={ProfileScreenPrimary}
        options={({route}) => ({
          title: 'List'
          headerTitleStyle: headerTitleStyle,
        })}
      />
)
}
 
  <Stack.Screen
        name="ProfileScreenSecondary"
        component={ProfileScreenSecondary}
        options={({route}) => ({
          title: `${!route.params.ProfileName ? myContext.profileName : route.params.ProfileName}`, -> this return route.params.ProfileName is undefined
          headerTitleStyle: headerTitleStyle,
        })}
      />
  <otherstack>
     )
QrQr
  • 141
  • 1
  • 13
  • Do you want to pass a default value ? or something that changes ? – Guruparan Giritharan Nov 19 '20 at 09:43
  • oops sorry i've edited the question, so i have two kind of user the firstone is admin who will get the list of data in the profileScreen Primary, and when he click the cards the user will be prompted to profileScreenSecondary with the data from route.params but when a customer account access the profile tab, i want to prompt him to profileScreenSecondary but with the data that i have in context nb: the admin have the same context too – QrQr Nov 19 '20 at 09:53
  • you can pass values as initialParams but it wont be updated unless its something like a value from the context – Guruparan Giritharan Nov 19 '20 at 09:59
  • 1
    damn i havent read the docs about initialParams, ill try that, thanks for the help sir – QrQr Nov 19 '20 at 19:23

0 Answers0