admin管理员组文章数量:1287633
I am using DrawerNavigator in .
const MyApp = DrawerNavigator({
Home: {
screen: MyHomeScreen,
},
Notifications: {
screen: MyNotificationsScreen,
},
});
I have multiple screens that are using MyNotificationsScreen
ponent with different props.
How can I do something like:
const MyApp = DrawerNavigator({
Home: {
screen: MyHomeScreen,
},
Notifications1: {
screen: MyNotificationsScreen(propName=val1),
},
Notifications2: {
screen: MyNotificationsScreen(propName=val2),
},
});
I am using DrawerNavigator in https://reactnavigation/docs/navigators/drawer.
const MyApp = DrawerNavigator({
Home: {
screen: MyHomeScreen,
},
Notifications: {
screen: MyNotificationsScreen,
},
});
I have multiple screens that are using MyNotificationsScreen
ponent with different props.
How can I do something like:
const MyApp = DrawerNavigator({
Home: {
screen: MyHomeScreen,
},
Notifications1: {
screen: MyNotificationsScreen(propName=val1),
},
Notifications2: {
screen: MyNotificationsScreen(propName=val2),
},
});
Share
Improve this question
edited May 29, 2017 at 20:42
Hristo Eftimov
15.8k14 gold badges54 silver badges79 bronze badges
asked May 29, 2017 at 18:15
AdamAdam
3,13811 gold badges48 silver badges80 bronze badges
2 Answers
Reset to default 11Better way in many cases I think:
screen: (props) => <MyNotificationsScreen {...props} propName={val1} />
This will put your nav props in props.navigation.state.params. If you want them to appear in this.props instead (which will mean your ponent is not tightly coupled to react-navigation) then use:
screen: (props) => <MyNotificationsScreen {...props.navigation.state.params} propName={val1} />
You do have two options here:
1- You pass the parameter in the 'navigate call':
this.props.navigation.navigate('Notifications1', {propName: 'val1'})
2- The other way around is to create Notifications1
class Notifications1
{
render ( )
{
return <MyNotificationsScreen propName="val1" />
}
}
本文标签: javascriptPassing props with screen option in DrawerNavigatorStack Overflow
版权声明:本文标题:javascript - Passing props with screen option in DrawerNavigator - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741253052a2366152.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论