First, react-day-picker was very helpful for me. thank you for you guys effort!!
and I'm not good at english. so I ask for your understanding : )
Is your feature request related to a problem? Please describe.
I followed the Example (http://react-day-picker.js.org/examples/selected-multiple )
and I wanted to get the difference between prevState.selectedDays and this.state.selectedDays in componentDidupdate function
but I couldn't. I thought this issue is about javascript immutability
In example page
handleDayClick(day, { selected }) {
const { selectedDays } = this.state;
if (selected) {
const selectedIndex = selectedDays.findIndex(selectedDay =>
DateUtils.isSameDay(selectedDay, day)
);
selectedDays.splice(selectedIndex, 1);
} else {
selectedDays.push(day);
}
this.setState({ selectedDays });
}
I think splice and push method break state's immutability
Describe the solution you'd like
In React, Keeping the state immutability is important
So.. I think it is better to update example page than now
this is example solution
handleDayClick(day, { selected }) {
const { selectedDays } = this.state;
const _selectedDays = selectedDays.concat()
if (selected) {
const selectedIndex = _selectedDays.findIndex(selectedDay =>
DateUtils.isSameDay(selectedDay, day)
);
_selectedDays.splice(selectedIndex, 1);
} else {
_selectedDays.push(day);
}
this.setState({ selectedDays: _selectedDays });
}
how do you guys think about this? : )
Thank you for your time to read this request
@doonguk, thanks for your suggestion. Definitely a bug in the example :) Would you mind to send a PR with the fix? The file is this one:
https://github.com/gpbl/react-day-picker/blob/v7/docs/src/code-samples/examples/selected-multiple.js
Going to publish this soon...
Most helpful comment
@doonguk, thanks for your suggestion. Definitely a bug in the example :) Would you mind to send a PR with the fix? The file is this one:
https://github.com/gpbl/react-day-picker/blob/v7/docs/src/code-samples/examples/selected-multiple.js