This is an odd question about react-datetime: Why doesn't the callback allow a "name" to be returned?
I'm using Daytime twice for "start" and "end" times on a calendar scheduler. But I want to use a single "onChange" event to update state. The problem is: Datetime onChange only returns the time, it doesn't return a name or an ID or any way for me to identify which Datetime component is sending the onChange.
Here is the render() code:
<CardSubtitle>Start Date:
<Datetime
value = {this.state.start}
onChange={this.handleChange}
className = "dateTimeModule"
/>
</CardSubtitle>
<CardSubtitle>End Date:
<Datetime
value = {this.state.end}
onChange={this.handleChange}
className = "dateTimeModule"
/>
</CardSubtitle>
And here is the logic I want to use:
handleChange = (e) => {
this.setState({
bodyEdit: true,
[e.target.name]:e.target.value
})
};
But "e" only contains the date object. It appears that Datetime doesn't support a "name" return?
I'm confused, it seems like an obvious miss. How do I differentiate between these? Do I need to write separate functions for each?
Thinking about doing this:
handleStartChange = (e) => {
this.setState({
startDate: e
})
};
handleEndChange = (e) => {
this.setState({
endDate: e
})
};
But this seems like unnecessary code.