Reputation: 681
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:
class Home extends Component {
componentWillMount(){
this.props.fetchMatches();
}
handleChange(newDateRange){
this.props.fetchMatches({
...this.props,
startDate: newDateRange[0],
endDate: newDateRange[1]
})
}
Upvotes: 0
Views: 666
Reputation: 5270
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. Either you'll have to explicitly bind this
or use arrow function
Upvotes: 1