Line 473, within date_picker.js, passes the internal state variable of "date" into the onChange user-defined function (passed in as a property); however, it fails to do anything with the function.
I wrote a function that is referenced within my onChange function definition. Below is the onChange property value, alongside the function I have created:
//Passing in fat arrow function via JSX property
onChange={(dates) => {selectLatestMonthDate(dates)}}
//onChange property will call the below function, when referenced within the DatePicker component.
//This function allows for the selection of multiple dates, but will only allow the user to select one date per
//month - maintain the latest date selected.
function selectLatestMonthDate(dates) {
dates = dates.filter(date => {
return dates.find(otherDate => {
return Number(otherDate.day) > Number(date.day)
&& Number(otherDate.month) == Number(date.month);
}) == undefined;
});
}
I have confirmed that DatePicker is calling my function, via a reference to the onChange property, and passing in an array of DateObjects (representing days that I have selected within the DOM). The problem is that my function, which overwrites the date array by removing some elements from the array, is not passed to the "setDate" state mutator within DatePicker. "SetDate" is called on line 469 - before the onChange call.
This is preventing me from modifying the date state via my onChange function. I cannot extend the behavior of multiple selection. Perhaps the "setDate" state reference can be moved to line 474, so that modifications within the onChange function are considered. This will make it very easy for developers to customize the multiple-select behavior, through onChange.
Otherwise, if this change is not made, I see no other way of modifying the state of this "stateless" component. The only other solution, would be to move to ES6 classes.
Thanks for your help.