我正在开发一个 React-Native 项目并发现了一个问题..
一切工作正常,除了我的 HomeStackScreen,我想通过 Prop 传递数据,但也想导航以打开抽屉
const HomeStackScreen = (props, navigation) => (
console.log("HOME STACK: " + props.studentData),
<HomeStack.Navigator headerMode="screen" studentData={props.studentData}>
<HomeStack.Screen name = "Home" children={() => <HomeScreen studentData={props.studentData} />} options={{
title:'Home',
headerStyle: {
backgroundColor: '#e67e22',
},
headerRight: () => (
<Icon.Button name="build" size={30}
backgroundColor="#e67e22" color="white" paddingLeft= {15} onPress= {() => navigation.
openDrawer()}></Icon.Button>
)
}}/>
</HomeStack.Navigator>
);
这是我的代码,但是当我编写时
const HomeStackScreen = (props) => (
或
const HomeStackScreen = ({navigation}) => (
一切正常,但是当我想同时使用两者时,我收到错误,告诉我其中一个不是函数
最佳答案
你应该像这样使用它们:
const HomeStackScreen = (props) => {
const {navigation,studentData} = props ;
return ...
}
关于reactjs - 无法在 React-Native 中使用导航 && 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65541407/