Apologies if this seems low effort but I have spent all day googling. I am trying to change the state of a date when a selection is made using the date picker. I am able to get this functionality to work by doing:
onDateChange={currentDate => this.setState({currentDate: currentDate})}
But if I try to turn this into a function:
onDateChange(currentDate) {
this.setState({currentDate: currentDate});
}
and then pass that function to onDateChange:
onDateChange={this.onDateChange}
This returns "cannot set state of undefined. The reason I am doing this is because I need the onDateChange function to execute in a parent component and then pass that prop down to this component. But I cannot even get the function to work in the child component. I have tried using an arrow function and but I am stumped. Can someone please tell me why this doesn't work as a function?
UPDATE:
Solved with
onDateChange={this.onDateChange} changed to {this.onDateChange.bind(this)}