Trying to set state in parent component (named parent.js) with a date selected in a child component named 'Book' in file 'daySelect.js' for taking down reservation details. Getting an error, though, saying the function (onUpdate) I'm calling from child to update state in parent is "not a function":
Parent Coding (parent.js):
class Parent extends Component {
// Setting the component's initial state
constructor(props) {
super(props);
this.state = {
date: "",
};
}
onUpdate = (dateChosen) => {
this.setState({
date: dateChosen
})
console.log(this.state.date);
};
render() {
return (
<div>
<Route exact path="/" component={Home} />
<Route exact path="/book" component={Book} onClick={this.onUpdate}/>
<Route exact path="/time" component={Time} />
<Route exact path="/form" component={Form} />
</div>
);
} }
Child Component:
class Book extends Component {
// Setting the component's initial state
constructor(props) {
super(props);
}
onClick = (date) => {
var dateChosen = date[0];
// console.log(dateChosen);
this.props.onUpdate(date);
this.setState({date: dateChosen});
};
render() {
return (
<div>
<ReactWeeklyDayPicker mobilView={window.innerWidth < 100} format={'YYYY-MM-DD'} selectDay={this.onClick.bind(this)} />
</div>
);
}
export default Book;