当我尝试更改react-redux中的状态属性时,出现错误Uncaught TypeError:无法读取未定义的属性“props”
,这是我要更改的代码:
class Home extends Component {
componentWillMount(){
this.props.fetchMatches();
}
handleChange(newDateRange){
this.props.fetchMatches({
...this.props,
startDate: newDateRange[0],
endDate: newDateRange[1]
})
}
最佳答案
执行以下操作:
handleChange = (newDateRange) => {
this.props.fetchMatches({
...this.props,
startDate: newDateRange[0],
endDate: newDateRange[1]
})
}
或者在构造函数中执行
constructor(){
super(props);
this.handleChange = this.handleChange.bind(this);
}
在handleChange
中,无法找到context
,因此this
未定义。您必须显式绑定(bind) this
或使用 arrow function
关于javascript - 未捕获的类型错误 : Cannot read property 'props' of undefined in react-redux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51233566/