【问题标题】:Getting Error using Props and Navigation in same - React Native 5x在同一使用道具和导航时出错 - React Native 5x
【发布时间】:2021-04-03 05:57:50
【问题描述】:

props.title 出现错误,这是我的代码 enter image description here

1: https://i.stack.imgur.com/Bjrb4.png 我收到了这个错误 enter image description here

navigation.Opendrawer 不工作...PFA...code 当我点击什么都没有发生

【问题讨论】:

    标签: react-native react-native-android react-native-navigation


    【解决方案1】:

    语法错误,用这个

    const CustomHeader = (props) => { 
        const {title, home} = props;
        ....
        props.navigation.goBack() 
    }
    

    const CustomHeader = ({title, home, navigation}) => {
       .....
       navigation.goBack() // <== No props.navigation
    }
    

    【讨论】:

    • 谢谢,它适用于 navigation.goBack ...但它不适用于 onPress= {() => navigation.openDrawer()
    【解决方案2】:

    请在 CustomerHeder 组件中指定传递给 prop 的值。

    <CustomerHeder title={"title"} isHome={"something"}/>
    
    
    const CustomerHeder = (props) => {
      
      const {title, isHome} = props   
    
    
       return ...
    }
    

    你也可以试试……

    const CustomerHeder = ({title , isHome}) => {
      
       
    
    
       return ...
    }
    

    【讨论】:

    • 感谢您的回答。我尝试了另一个有效的...
    猜你喜欢
    • 2019-12-29
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    • 2019-07-22
    • 2022-06-26
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    相关资源
    最近更新 更多