I need to pass the navigation object (the one I receive, for example, using useNavigation()
) as a prop to a component. The issue is that the one I’m interested in is the navigation object of a nested navigation:
...
export function AddDeviceWizard({navigation}){
const Stack = createStackNavigator(); //Here i create a nested navigator
return (
<BaseScreen
navigator={nestedNavigation} //this is te nav i need, not the one who brought me here
>
<Stack.Navigator initialRouteName="addDevice1">
<Stack.Screen name="addDevice1" component={AddDevice1}/>
<Stack.Screen name="addDevice2" component={AddDevice2} />
</Stack.Navigator>
<BaseScreen/>
)}
If I use useNavigation()
, I’ll get the navigation object of the main navigation, the one that brought me to this component. What I’m doing now is a bit tricky, passing the navigation object down through a context from addDevice1
(the first screen that loads), which receives it as a parameter of initialization (… export function AddDevice1({ navigation }) {...}
).
Is there any method or property when creating a StackNavigator
that allows me to access what I need so that I don’t have to grab it in the rendered screens and push it up with a context?
AleH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.