Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set initial tab in react navigation TabNavigator dynamically

I am using react-navigation and have a nested TabNavigator inside a StackNavigator. I have three tabs in TabNavigator and need to set initialRouteName for TabNavigator dynamically based on some logic.

I have tried putting the TabNavigator inside a React Component with dynamically selected initial tab and used in StackNavigator with passing props through screenProps of TabNavigator. But this way I am unable to navigate to any route of StackNavigator.

Is there any way to make initialRouteName dynamically.

Note: I am not using redux for this application.

like image 457
Natwar Singh Avatar asked Oct 17 '22 19:10

Natwar Singh


1 Answers

<Tab.Navigator
 initialRouteName="YOUR_TAB_NAME"
 ... 
/>

...

Reference:https://reactnavigation.org/docs/bottom-tab-navigator/#initialroutename

like image 81
hakkikonu Avatar answered Oct 21 '22 06:10

hakkikonu