const onChange = (type) => (e) => {
const [value, setValue] = useState({
StartDate : new Date("2021-03-24T23:59:59"),
EndDate : new Date("2021-03-24T23:59:59"),
Seperate : false
});
if (type == "StartDate" || type == "EndDate") {
console.clear();
setValue({
...value,
[type]: new Date(e),
});
} else {
setValue({
...value,
[type]: e.target.value == "on" ? !value[type] : e.target.value,
});
}
};
<Form.Control as="select" onChange={onChange("Consolidation")}>
<DateTimePicker onChange={onChange("StartDate")}
onChange={onChange("StartDate")}
Attempting to understand %100 the above. And I am confused by one item in the above.
- What is the purpose of the second (e) in the above function? I know this is the event handler, yet how is this passed to the onChange function from the form controls, being it is only defined with the type parameter.
I guess the additional => (e) is confusing me. Thanks for your time.