如何在本地本机的一个功能组件中一起使用道具和导航

问题描述 投票:0回答:1

我想在props版本5的一个功能组件中使用{navigation}react-navigation

这是我的代码:

const Header =(props, {navigation})=>{

return()}

但是它不起作用,我无法激活抽屉。它返回以下错误:

undefined is not an object(evaluating 'navigation.openDrawer)
javascript reactjs react-native react-navigation react-functional-component
1个回答
0
投票

您需要查找解构:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

示例:

const Header = (props)=> {
  const { navigation } = props;

  // Now you can use `navigation`
  // Instead of destructuring, you can also use `props.navigation`
}
© www.soinside.com 2019 - 2024. All rights reserved.