Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Can´;t使用导航和&;《反应本族语》中的道具?_Reactjs_React Native - Fatal编程技术网

Reactjs Can´;t使用导航和&;《反应本族语》中的道具?

Reactjs Can´;t使用导航和&;《反应本族语》中的道具?,reactjs,react-native,Reactjs,React Native,我正在进行React本地项目,发现了一个问题 除了我的HomeStackScreen外,一切都正常,我想通过道具传递数据,但也想导航打开抽屉 const HomeStackScreen = (props, navigation) => ( console.log("HOME STACK: " + props.studentData), <HomeStack.Navigator headerMode="screen" stude

我正在进行React本地项目,发现了一个问题

除了我的HomeStackScreen外,一切都正常,我想通过道具传递数据,但也想导航打开抽屉

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 {navigation,studentData} =  props ;
  return ...

}

将道具作为对象传递,并:

const HomeStackScreen = ({navigation, studentData}) => (


  console.log("HOME STACK:   " + studentData),

  <HomeStack.Navigator headerMode="screen" >
    <HomeStack.Screen name = "Home" children={() => <HomeScreen studentData={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=({navigation,studentData})=>(
log(“主堆栈:+studentData”),
}选择权={{
标题:"家",,
头型:{
背景颜色:“#e67e22”,
},
头灯:()=>(
航行
openDrawer()}>
)
}}/>
);

props.studentData有效吗?是的,props.studentData非常有效!它可以工作-我使用你的代码和restartedHappy来帮助你:)来自Angular,非常新的React(本机)-在道具、状态等方面仍然有一些问题。干得好,祝你一切顺利。thx,但同样的错误出现了
const HomeStackScreen = (props) => {
  const {navigation,studentData} =  props ;
  return ...

}
const HomeStackScreen = ({navigation, studentData}) => (


  console.log("HOME STACK:   " + studentData),

  <HomeStack.Navigator headerMode="screen" >
    <HomeStack.Screen name = "Home" children={() => <HomeScreen studentData={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>

);