【问题标题】:react native component has no access to props - TypeError: Cannot read property ‘navigation’ of undefined反应本机组件无法访问道具-TypeError:无法读取未定义的属性“导航”
【发布时间】:2018-05-25 09:43:58
【问题描述】:
enter image description here
TypeError:无法读取未定义的属性“导航”?
看起来我的组件无法访问 this.props.navigation.(react-navigation)
基本上,每当我调用时,我都会收到此错误: const { navigate } = this.props.navigation.
知道如何让组件访问 this.props.navigation 吗?
【问题讨论】:
标签:
react-native
react-navigation
【解决方案1】:
ES6 类不会自动绑定 this。有一些解决方案,例如在构造函数中绑定或将其更改为箭头函数:
renderRow = ({ item }) => {
// rest of code
}