I believe the nuance here that I need to understand is borne out of updating a nested state, if I could understand Wale's logic here, and how it applies to my example that'd be great.
I've tried this following code:
NewNotePage.js //where this.state.note.date is updated
class NewNotePage extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
note: {
title: "",
body: "",
createdAt: null,
updatedAt: null,
date:null
}
};
this.handleDate = this.handleDate.bind(this);
this.handleTime = this.handleTime.bind(this);
}
handleDate = date => this.setState({ date })
handleTime = date => this.setState({ date })
render() {
console.log(this.state.note.date)
const { note } = this.state;
return (
<div>
<PickerDrawer
show={this.state.drawerOpen}
date={this.state.note.date}
handleTime={this.handleTime}
handleDate={this.handleDate} />
{backdrop}
</div>
);
}
}
PickerDrawer.js //where this.props.note.date is selected
class PickerDrawer extends React.Component {
constructor(props) {
super(props);
render(props) {
return (
<div className={drawerClasses}>
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<DatePicker
label="Due Date"
value={this.props.date}
onChange={this.props.handleDate}
animateYearScrolling
showTodayButton={true}
disablePast={true}
/>
<TimePicker
label="Time"
value={this.props.date}
onChange={this.props.handleTime}
animateYearScrolling
/>
</MuiPickersUtilsProvider>
</div>
);
}
}
console.log(this.state.note.date) in NewNotePage throws null, as it is in initial state