javascript - 在 js-react native 中访问 props 和 navigation
问题描述
我正在尝试将道具和 {navigation, route} 放在同一个函数中,但它不起作用。我什至尝试声明一个变量而不是 prop,但这也不起作用。代码如下所示。某人可以告诉我我做错了什么。
function CustomDrawerContent(props, {navigation, route}) {
//const { navigation } = props;
const onSignOut = props.onSignOut ;
return (
<DrawerContentScrollView {...props}>
<View>
<Text> MENU </Text>
</View>
<DrawerItemList {...props} />
<DrawerItem
label="Logout"
onPress={onSignOut}
/>
<DrawerItem
icon={(props) => <Ionicons name="ios-exit" {...props} />}
label="close drawer"
onPress={() => navigation.closeDrawer()}
/>
</DrawerContentScrollView>
);
}
解决方案
最好的方法是在as parameter of your component or to destructure the
里面传递````props props``` 对象,但不要同时做这两个。你试过这样做吗?使用您需要的属性来解构 props 对象:
function CustomDrawerContent(props) {
const { navigation, route, onSignOut } = props;
推荐阅读
- node.js - 如何使用node_redis对多个队列进行BLPOP、BRPOP操作
- ruby - 如何从 crontab 运行脚本并避免“LoadError”
- angular - Angular Ionic 4如何使用Route正确传递变量
- r - 如何读取在数据框中提供文件名的多个选择性 JPEG 文件?
- typescript - 将 Intersect / Union 定义为接口属性上的标记
- command-line - 在 Snowsql 中,当我尝试“放置”文件时,我收到以下错误消息:
- react-native - [React Native][Expo] 当文本在文本组件中换行到多行时,文本对齐中断
- javascript - countBy 使用下划线 - 选择计数避免重复
- ios - 如何根据日期(部分)对 UITableView(聊天气泡)中的消息进行分组?
- postgresql - 如何为现有的 postgres 数据库创建用户(读写和只读)和管理员角色?