在js中访问道具和导航都是原生的



我试图将prop和{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>
);
}

最好的方法是在内部传递```propsas parameter of your component or to destructure theprops```对象,但不能同时执行这两种操作。你试过这样做吗?Juts用你需要的属性破坏道具对象:

function CustomDrawerContent(props) {
const { navigation, route, onSignOut } = props;

最新更新