[英]Uncaught TypeError: Cannot read property 'props' of undefined in react-redux
i got the error Uncaught TypeError: Cannot read property 'props' of undefined
when i tried to change the props of state in react-redux, here's my code to change: 我收到错误
Uncaught TypeError: Cannot read property 'props' of undefined
当我尝试更改react-redux中的状态道具时, Uncaught TypeError: Cannot read property 'props' of undefined
,这是我要更改的代码:
class Home extends Component {
componentWillMount(){
this.props.fetchMatches();
}
handleChange(newDateRange){
this.props.fetchMatches({
...this.props,
startDate: newDateRange[0],
endDate: newDateRange[1]
})
}
Do the following: 请执行下列操作:
handleChange = (newDateRange) => {
this.props.fetchMatches({
...this.props,
startDate: newDateRange[0],
endDate: newDateRange[1]
})
}
or in constructor, do 或在构造函数中
constructor(){
super(props);
this.handleChange = this.handleChange.bind(this);
}
In handleChange
, it is not able to find the context
, due to which this
is undefined. 在
handleChange
,它是不是能够找到context
,由于它this
是不确定的。 Either you'll have to explicitly bind this
or use arrow function 您将必须明确绑定
this
或使用箭头功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.