Uncaught TypeError: Cannot read property 'props' of undefined in react-redux
Uncaught TypeError: Cannot read property 'props' of undefined in react-redux
当我尝试在 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]
})
}
执行以下操作:
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
未定义。您必须显式绑定 this
或使用 arrow function
当我尝试在 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]
})
}
执行以下操作:
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
未定义。您必须显式绑定 this
或使用 arrow function