本机组件无法访问道具 - TypeError:无法读取未定义的属性'navigation'

[英]react native component has no access to props - TypeError: Cannot read property ‘navigation’ of undefined


enter image description here

在此处输入图像描述

TypeError: Cannot read property ‘navigation’ of undefined? Looks like my component has no access to this.props.navigation.( react-navigation) Basically I get this error whenever I call: const { navigate } = this.props.navigation.

TypeError:无法读取undefined的属性'navigation'?看起来我的组件无法访问this.props.navigation。(react-navigation)每当我调用时,基本上我都会收到此错误:const {navigate} = this.props.navigation。

Any idea how to give the component access to this.props.navigation ?

知道如何让组件访问this.props.navigation吗?

1 个解决方案

#1


1  

ES6 classes don't autobind this. There's a few solutions to this like binding in the constructor or just changing it to an arrow function:

ES6课程不会自动提出这个问题。有一些解决方案,比如构造函数中的绑定或只是将其更改为箭头函数:

renderRow = ({ item }) => {
  // rest of code
}

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/12/11/d4e93c345a76064858471e2ece5c5d6b.html



 
  © 2014-2022 ITdaan.com