How to send Params data to the screen which is in drawer stack.
here is my code from login screen I want to send loginAs data to the homeScreen which is in MyDrawer stack.
onPress={() => this.props.navigation.navigate("MyDrawer", {loginAs : `${this.state.nature}`})}
here is my MyDrawer stack
function App({ navigation }) {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="loginScreen" component={loginScreen} options={{headerShown: false}} />
<Stack.Screen name="MyDrawer" component={MyDrawer} options={{headerShown: false}} />
</Stack.Navigator>
</NavigationContainer>
);
}
function MyDrawer({ navigation }) {
return (
<Drawer.Navigator initialRouteName="homeScreen">
<Drawer.Screen name="homeSreen" component={homeScreenStack}
options={{drawerLabel: 'Home',}}
/>
</Drawer.Navigator>
);
}
You navigate directly to your homeScreen
like this
onPress={() => this.props.navigation.navigate("homeScreen", {loginAs : `${this.state.nature}`})}
And then in your homeScreenStack
component you get your params
like you'd noramlly do
const loginAs = navigation.params?.loginAs;
Note: you have a typo in the name
property of your Drawer.Screen
you typed homeSreen
instead of homeScreen
so be aware of that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.